code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

02 Even Fibonacci

function fiboEvenSum(n) {
    const arr = [1, 2];
    let sum = 0;
    for(let i = 2; i<=n; i++)
    {
        arr.push(arr[i-2] + arr[i-1])
    }
    arr.forEach((value) => {
        if(value % 2 === 0){
            sum += value;
        }
    })
    return sum;
}
  
console.log(fiboEvenSum(10));

Created 2019-11-24T04:41:20+05:18 · Edit