Earn extra honor and gain new allies!
Honor is earned for each new codewarrior who joins.
Learn more
Algorithms
Code
Diff
  • const getDividors = n => {
      
      let result = [];
    
      for (let i = 1; i <= Math.floor(Math.sqrt(n)); i += 1)
        if (n % i === 0) { result.push(i); if (n / i !== i) result.push(n / i) }
        
      return result; // output array won't be sorted
      
    }
  • 1-const getDividors = (n, result = []) => {
    1+const getDividors = n => {
    2+
    3+ let result = [];
    22
    3- for (let i = 1; i <= Math.floor(Math.sqrt(n)); i++)
    5+ for (let i = 1; i <= Math.floor(Math.sqrt(n)); i += 1)
    44 if (n % i === 0) { result.push(i); if (n / i !== i) result.push(n / i) }
    55
    66 return result; // output array won't be sorted
    77
    88 }
Algorithms
Code
Diff
  • const flatten = arr =>
      arr.reduce((acc, item) =>  acc.concat(Array.isArray(item) ? flatten(item) : item), []);
  • 11 const flatten = arr =>
    2- arr.reduce((acc, item) => acc.concat(Array.isArray(item) ? flatten(item) : [item]), []);
    2+ arr.reduce((acc, item) => acc.concat(Array.isArray(item) ? flatten(item) : item), []);
Algorithms
const flatten = arr =>
  arr.reduce((acc, item) => Array.isArray(item) ? [...acc, ...flatten(item)] : [...acc, item], []);
Algorithms

The fastest way to find all dividors of a number.

const getDividors = (n, result = []) => {   

  for (let i = 1; i <= Math.floor(Math.sqrt(n)); i++)
    if (n % i === 0) { result.push(i); if (n / i !== i) result.push(n / i) }
    
  return result; // output array won't be sorted
  
}