Ad
Algorithms
Mathematics
  • Changed Array.from to the more modern spread syntax. Ppopulates with range of numbers rather than undefined.

  • Allows us to use the direct value in map rather than index

  • Allows us to use slice rather than subtracting 2 then adding back later

  • Changed .some to .every so we don't have to deal with double negatives.

  • Changed to math ceil as we always want the larger number. Some tests fail if rounded down as we need the upper limit to be inclusive.

Code
Diff
  • function prime_checker(n) {
      return n <= 1 ? false : [...Array(Math.ceil(Math.sqrt(n))).keys()].slice(2).every((v) => n % v);
    };
    • function prime_checker(n){
    • return n <= 1 ? false : !Array.from({ length: Math.round(Math.sqrt(n)) - 2 }).some((v, i) => n % (i + 2)===0)
    • }
    • function prime_checker(n) {
    • return n <= 1 ? false : [...Array(Math.ceil(Math.sqrt(n))).keys()].slice(2).every((v) => n % v);
    • };
Code
Diff
  • const countVowel = str => --str.split(/[aeiou]/i).length;
    
    • const countVowel = str => str.split(/[aeiou]/i).length - 1
    • const countVowel = str => --str.split(/[aeiou]/i).length;