Skip to content

Instantly share code, notes, and snippets.

@yurist38
Created August 8, 2019 07:40
Show Gist options
  • Save yurist38/d5e83e228c72d681e8e202553df9ebde to your computer and use it in GitHub Desktop.
Save yurist38/d5e83e228c72d681e8e202553df9ebde to your computer and use it in GitHub Desktop.
Daily Challenge #35 - Find the Outlier
void main() {
print(findOutlier([2, 4, 0, 100, 4, 11, 2602, 36]));
print(findOutlier([160, 3, 1719, 19, 11, 13, -21]));
print(findOutlier([4, 8, 15, 16, 24, 42]));
print(findOutlier([16, 6, 40, 66, 68, 28]));
}
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];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment