loading...

re: Daily Challenge #256 - How Many Are Smaller Than I? VIEW POST

FULL DISCUSSION
 
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;
  })
}
Code of Conduct Report abuse