DEV Community

loading...

Discussion on: Daily Challenge #256 - How Many Are Smaller Than I?

Collapse
davejs profile image
David Leger
const smaller = (arr: number[]): number[] => {
  // loop over items
  return arr.map((item, i) => {
    // get array of remaining items
    const rest = arr.slice(i + 1, arr.length);

    // filter for items less than the current item
    const lessThan = rest.filter(curr => curr < item);

    // count the items less than
    return lessThan.length;
  })
}