javascript factor chain

Solutions on MaxInterview for javascript factor chain by the best coders in the world

showing results for - "javascript factor chain"
Denny
16 Oct 2020
1function factorChain(arr) {
2	for (let i = 0; i < arr.length - 1; i++) {
3		if ((arr[i + 1] % arr[i]))
4			return false
5	}
6	return true
7}
Melody
21 Nov 2016
1const factors = number => [...Array(number + 1).keys()].filter(i=>number % i === 0);
2console.log(factors(36));      //  [1, 2, 3, 4, 6, 9, 12, 18, 36]
Lou-Anne
03 May 2018
1function factorChain (arr) {
2	return arr.reduce((a, c, i) => arr[i] % arr[i-1] === 0);
3}
Chiara
22 Sep 2019
1function factorChain(num) {
2 let n = num.slice(num.length - 1, num.length)[0]
3 return [...Array(n + 1).keys()]
4	 .filter(v => n % v === 0)
5	 .map((v, i) => v === num[i])[0]
6}
Leonie
07 Oct 2017
1const factors = number => Array
2    .from(Array(number + 1), (_, i) => i)
3    .filter(i => number % i === 0)
4
5 console.log(factors(36));      //  [1, 2, 3, 4, 6, 9, 12, 18, 36]
Lisa
11 Sep 2020
1function calculate(num) {
2    var str = "0";
3    for (var i = 1; i <= num; i++) {
4        if (num % i == 0) {
5            str += ',' + i;
6        }
7    }
8    alert(str);
9}
10
11calculate(232);