-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetPowerNumber.js
More file actions
38 lines (30 loc) · 849 Bytes
/
Copy pathgetPowerNumber.js
File metadata and controls
38 lines (30 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function checkIfPowerNumber3(num){
limit = parseInt(Math.sqrt(num))+1
for (var x=2; x<limit; x++){
b = Math.log(num)/Math.log(x);
// console.log(b)
b = precisionRound(b, 10)
if (b == parseInt(b)){
return true
}
}
return false
}
function precisionRound(number, precision) {
var factor = Math.pow(10, precision);
console.log("precision" , Math.round(number * factor) / factor);
return Math.round(number * factor) / factor;
}
function getPowerNumber(index){
var list_nums = []
var start = 4
while ((list_nums.length) != index+1) {
if (checkIfPowerNumber3(start)){
list_nums.push(start)
}
start+=1
}
// console.log(list_nums)
return list_nums[index]
}
console.log(getPowerNumber(2))