javascript factor chain code example
Example 1: javascript factor chain
function factorChain(arr) {
for (let i = 0; i < arr.length - 1; i++) {
if ((arr[i + 1] % arr[i]))
return false
}
return true
}
Example 2: javascript factor chain
function factorChain (arr) {
return arr.reduce((a, c, i) => arr[i] % arr[i-1] === 0);
}
Example 3: 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 4: 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 5: javascript factor chain
const factors = number => [...Array(number + 1).keys()].filter(i=>number % i === 0);
console.log(factors(36));
Example 6: javascript factor chain
const factors = number => Array
.from(Array(number + 1), (_, i) => i)
.filter(i => number % i === 0)
console.log(factors(36));