DEV Community

Discussion on: Daily Challenge #35 - Find the Outlier

Collapse
 
room_js profile image
JavaScript Room

Dart solution:

findOutlier(List nums) {
  var odds = new List();
  var evens = new List();
  nums.forEach((num) => num % 2 == 0 ? evens.add(num) : odds.add(num));

  if (odds.length == 0 || evens.length == 0) { return null; }

  return (odds.length < evens.length ? odds : evens)[0];
}

Link to the online playground: dartpad.dartlang.org/d5e83e228c72d...