24 Days Of JavaScript mas
Level up your JavaScript skills with a daily coding challenge from December 1st to 24th.
Every day, we'll pick a winner who gets Scrimba Pro for a year (worth $150).
On Christmas Eve, a winner gets $1000.
fibonacci
function sumOddFibonacciNumbers(num) {
let num1 = 0;
let num2 = 1;
let oddFibonacciSum = 1;
while (true) {
let nextFib = num1 + num2;
num1 = num2;
num2 = nextFib;
if (nextFib > num) {
break;
}
if (nextFib % 2 === 1) {
oddFibonacciSum += nextFib;
}
}
return oddFibonacciSum;
}
sumOddFibonacciNumbers(4000000);
// 4613732
refs
https://scrimba.com/learn/adventcalendar
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!