Skip to content

Commit

Permalink
add (programmers - level1 1문제): js 풀이
Browse files Browse the repository at this point in the history
  • Loading branch information
padosum committed Dec 22, 2022
1 parent 5654e2a commit 8e550d6
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions programmers/level1/기사단원의 무기.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function solution(number, limit, power) {
const numbers = Array.from({ length: number }, (v, i) => i + 1);

const divisorsCnt = numbers.map(num => {
let count = 0;
for (let i = 1; i <= Number(Math.sqrt(num)); i++) {
if (num % i == 0) {
if (Number(Math.sqrt(num)) === i) {
count += 1;
} else {
count += 2;
}
}
}
return count;
});

const result = divisorsCnt.reduce((acc, curr) => {
if (curr > limit) {
return acc + power;
} else {
return acc + curr;
}
}, 0);

return result;
}

0 comments on commit 8e550d6

Please sign in to comment.