factor chain array javascript code example
Example 1: javascript factor chain
function factorChain(num) {
let n = num.slice(num.length - 1, num.length)[0]
return [...Array(n + 1).keys()]
.filter(v => n % v === 0)
.map((v, i) => v === num[i])[0]
}
Example 2: javascript factor chain
function factorChain (arr) {
return arr.reduce((a, c, i) => arr[i] % arr[i-1] === 0);
}