알고리즘 42 - Square Every Digit

tamagoyakii·2021년 10월 14일
0

알고리즘

목록 보기
42/89

Q.

Welcome. In this kata, you are asked to square every digit of a number and concatenate them.

For example, if we run 9119 through the function, 811181 will come out, because 92 is 81 and 12 is 1.

Note: The function accepts an integer and returns an integer

A)

function squareDigits(num){
  return +String(num).split('').map(el => el * el).join('')
}

map 처음 써봤다. 아직 자세한 사용법은 모른다. 고차함수 배우는 날 다시 알아가야겠다.

0개의 댓글