DEV Community

Discussion on: Daily Challenge #13 - Twice Linear

Collapse
 
nans profile image
Nans Dumortier • Edited

Not sure I have well understood this one ... Am I correct with this JS function ? 🙈

const doubleLinear = (n) => {
  let u = [1];
  let i = 0;
  while(i < n) {
    u = [...u, u[i] * 2 + 1, u[i] * 3 + 1];
    u = Array.from(new Set(u))
    u.sort((a, b) => a - b);
    i++;
  }
  return u;
}

EDIT: added the line u = Array.from(new Set(u)) to get unique values !