24 Days Of JavaScript mas
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 发布文章使用:只允许注册用户才可以访问!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/14075966.html
未经授权禁止转载,违者必究!