map filter chaining in javascript code example
Example 1: javascript factor chain
const factors = number => [...Array(number + 1).keys()].filter(i=>number % i === 0);
console.log(factors(36));
Example 2: javascript factor chain
function calculate(num) {
var str = "0";
for (var i = 1; i <= num; i++) {
if (num % i == 0) {
str += ',' + i;
}
}
alert(str);
}
calculate(232);
Example 3: 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]
}