+ 1

Write a JavaScript program to get all the factors of no.

JavaScript

19th Apr 2018, 8:57 AM
Ankita Samal
Ankita Samal - avatar
4 Answers
+ 2
thanks
19th Apr 2018, 4:15 PM
Ankita Samal
Ankita Samal - avatar
+ 1
I don't understand plseee give me solution in simple format
19th Apr 2018, 9:32 AM
Ankita Samal
Ankita Samal - avatar
+ 1
Hi Ankita Here is solution using ES6 JavaScript function factor(x){ //range creates an array of all whole numbers 1 to x function range(x){ let arr=[...Array(x).keys()]; return arr.map(x=>x+1); } //filter out numbers divisible by x return range(x).filter( function(ele,index,array){ if ((array.length/ele)%1===0) return(ele); }); } console.log(""+factor(20)); //1,2,4,5,10,20
19th Apr 2018, 2:56 PM
Mike Choy
Mike Choy - avatar