DEV Community

Discussion on: Daily Challenge #82 - English Beggars

Collapse
 
delixx profile image
DeLiXx • Edited

An computation-on-demand approach in js

function beggars(arr, count) {
    return (i) => {
        let loot = 0;
        for(; i < arr.length; i += count) loot += arr[i];
        return loot;
    }
}
let a = beggars([1,2,3,4,5],2);