DEV Community

Discussion on: Daily Challenge #35 - Find the Outlier

Collapse
 
vince_tblt profile image
Vincent Thibault

You only need to fetch the firsts 3 items to know what you are searching for.

function findOutlier (list: number[]): number | void {
  const search = list.slice(0,3).filter(v => v % 2).length > 1 ? 0 : 1;
  return list.find(v => v % 2 === search);
}