CodeWars 코딩 문제 2021/01/25 - Square Every Digit
[문제]
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
(요약) 문자열 각 숫자를 제곱해서 연결한걸 return
.
[풀이]
function squareDigits(num){
let answer = '';
num = num + '';
for(let k in num) {
answer += num[k] * num[k];
}
return answer * 1;
}
숫자를 문자열로 바꿔서 반복문 돌림.
Author And Source
이 문제에 관하여(CodeWars 코딩 문제 2021/01/25 - Square Every Digit), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://velog.io/@hemtory/CodeWars20210125
저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
function squareDigits(num){
let answer = '';
num = num + '';
for(let k in num) {
answer += num[k] * num[k];
}
return answer * 1;
}
숫자를 문자열로 바꿔서 반복문 돌림.
Author And Source
이 문제에 관하여(CodeWars 코딩 문제 2021/01/25 - Square Every Digit), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@hemtory/CodeWars20210125저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)