We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c45bd34 commit 576c5dfCopy full SHA for 576c5df
bona1122/[week6]Set/Prime_factors.js
@@ -0,0 +1,15 @@
1
+// https://school.programmers.co.kr/learn/courses/30/lessons/120852
2
+
3
+// n이 주어질때, n의 소인수를 오름차순으로 담은 배열 리턴하기
4
+function solution(n) {
5
+ const factors = new Set()
6
+ for (let i = 2; i * i <= n; i++) {
7
+ while (n % i === 0) {
8
+ factors.add(i)
9
+ n /= i
10
+ }
11
12
+ // 마지막으로 남은 수가 1보다 크면 그 자체가 소수이므로 추가
13
+ if (n > 1) factors.add(n)
14
+ return Array.from(factors)
15
+}
0 commit comments