๋ฐ์ํ

๋ฐฉ๋ฒ1
const solution = (arr) => {
let newArr = []
for(let x of arr){
let newarr = x.toString().split('').reverse().reduce((a,b) => a+b,0)
newArr.push(Number(newarr))
}
console.log(newArr);
}
solution([32, 55, 62, 20, 250, 370, 200, 30, 100])
// ๊ฒฐ๊ณผ
[ 23, 55, 26, 2, 52, 73, 2, 3, 1 ]
๋ฐฉ๋ฒ2
const solution = (arr) => {
let newArr = []
for(let x of arr){
let result = 0;
while(x){
let t = x % 10;
result = result * 10 + t;
x = parseInt(x/10);
}
newArr.push(result)
console.log(newArr)
}
}
solution([32, 55, 62, 20, 250, 370, 200, 30, 100])
// ๊ฒฐ๊ณผ
[ 23, 55, 26, 2, 52, 73, 2, 3, 1 ]
๐ ์๋ชป๋ ๊ฐ๋ ์ ๋ฌ์ด ์๋ค๋ฉด ๋๊ธ ๋ถํ๋๋ฆฝ๋๋ค. ์ ์ ์ฑ์ฅ์ ํฐ ๋์์ด ๋ฉ๋๋ค๐ค
๋ฐ์ํ
'๐ฌComputer Science > ์ฝ๋ฉํ ์คํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋๊ฐ์ ์คํ์ผ๋ก ํ ๊ตฌํํ๊ธฐ (0) | 2022.12.07 |
---|---|
ํน์ ๊ฐ์ผ๋ก ๋ฐฐ์ด ๋ง๋ค์ด์ ์ฑ์ฐ๊ธฐ (0) | 2022.08.11 |
์ซ์๋ฅผ ํ๋์ฉ ์ชผ๊ฐ๋ ๋ฐฉ๋ฒ / ๋ฐฑ์ค 2588๋ฒ ๊ณฑ์ (0) | 2022.08.01 |
forEach, map, filter, reduce ๋ฉ์๋ ์๋์๋ฆฌ ์ ๋ฆฌ (0) | 2022.07.27 |
๋์ด ์ฐ์ ํ์ (BFS) (0) | 2022.07.04 |