ddstats-server/libs/utils/multithread/fibonacci.js

29 lines
725 B
JavaScript
Raw Normal View History

2021-10-13 19:45:59 +02:00
import initLog from '../log.js'
2021-10-13 19:45:59 +02:00
const log = initLog('Fibonacci')
2021-10-13 19:45:59 +02:00
export function main(data) {
return new Promise(
(resolve, reject) => {
let nums = [1, 1]
for (let i = 0; i < 44; i++) {
nums.push(nums[nums.length - 2] + nums[nums.length - 1])
}
let primes = []
for (const num of nums) {
let isPrime = true
for (let i = 2; i < num / 2; ++i) {
if (num % i === 0)
isPrime = false
}
if (isPrime)
primes.push(num)
}
2021-10-13 19:45:59 +02:00
resolve(primes)
}
)
}