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

29 lines
725 B
JavaScript

import initLog from '../log.js'
const log = initLog('Fibonacci')
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)
}
resolve(primes)
}
)
}