[Programmers Lv.0 | JS] 자릿수 더하기

Bori·2023년 2월 22일
0

Algorithm

목록 보기
11/26
post-thumbnail

프로그래머스 자릿수 더하기 문제 링크

나의 풀이

function solution(n) {
    return n.toString().split('').reduce((prev, curr) => +prev + +curr, 0);
}

다른 풀이를 보면서

Array.prototype.map()

Syntax
// Arrow function
map((element) => { /* … */ })
map((element, index) => { /* … */ })
map((element, index, array) => { /* … */ })

// Callback function
map(callbackFn)
map(callbackFn, thisArg)

// Inline callback function
map(function (element) { /* … */ })
map(function (element, index) { /* … */ })
map(function (element, index, array) { /* … */ })
map(function (element, index, array) { /* … */ }, thisArg)

0개의 댓글