[CodeKata] JavaScript

임창현·2022년 11월 27일
0

문제

문자로 구성된 배열을 input으로 전달하면, 문자를 뒤집어서 return 해주세요.

새로운 배열을 선언하면 안 됩니다.
인자로 받은 배열을 수정해서 만들어주세요.

Input: ["h","e","l","l","o"]
Output: ["o","l","l","e","h"]

Input: ["H","a","n","n","a","h"]
Output: ["h","a","n","n","a","H"]

나의 풀이

let a = "1+3i"
let b = "1+-2i"

a = a.slice(0,-1)
b = b.slice(0,-1)

a = a.split('+').map(Number)
b = b.split('+').map(Number)

let first = a[0]*b[0] 
let second = a[0]*b[1] + a[1]*b[0]
let third = a[1]*b[1]*-1

second+"i"

first+third+"+"+second+"i"
profile
Hi there 👋 i'm backend developer

0개의 댓글