+ 1
Write a JavaScript program to get all the factors of no.
JavaScript
4 Respuestas
+ 2
thanks
+ 1
I don't understand plseee give me solution in simple format
+ 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