Ad

Trimmed the lambda

Code
Diff
  • function getGemsOfColor(color, gems) {
      return gems.filter(gem => gem.colors.includes(color)).map(it => it.name).sort();
    }
    • function getGemsOfColor(color, gems) {
    • return gems.filter(gem => gem.colors.includes(color)).map(it => {return it.name}).sort();
    • return gems.filter(gem => gem.colors.includes(color)).map(it => it.name).sort();
    • }
Code
Diff
  • function returnhundred(n = 0) {
      if (n % 5 - 4 || n % 11) return returnhundred(n + 3);
      return n + 1;
    }
    • function returnhundred() {
    • return 10 ** 2;
    • function returnhundred(n = 0) {
    • if (n % 5 - 4 || n % 11) return returnhundred(n + 3);
    • return n + 1;
    • }

What's the most efficient algorithm to find the prime divisors of a number?

function divisors(x) {
  if (x === 1) return [];
  let sqrt = Math.sqrt(x);
  let res = [];
  while (x % 2 === 0) {
    x /= 2;
    res.push(2);
  }
  for (let n = 3; n <= sqrt && x > 1; n += 2) {
    if (x % n === 0) {
      x /= n;
      sqrt = Math.sqrt(x);
      res.push(n);
      n -= 2;
    }
  }
  if (x > 1) res.push(x);
  return res;
}

Using the bitwise not operator; it will only work with integers.

Code
Diff
  • neg = _ => ~_ + 1
    // this only works with integers
    • function neg(number) {
    • return -(number);
    • }
    • neg = _ => ~_ + 1
    • // this only works with integers

This is just to demonstrate how to do this without regexp, yet in a short way.

Code
Diff
  • count=str=>str.split("").filter(x=>x=="a"||x=="A").length;
    • function count(string) {
    • }
    • count=str=>str.split("").filter(x=>x=="a"||x=="A").length;