Here's my code: I believe I could have used filters on the arrays method but just decided to follow the long step.
const findOutlier = (arr) => { const evens = []; const odds = []; for(let i in arr) { const isEven = arr[i] % 2 === 0; const isOdd = !isEven; if(isEven){ evens.push(arr[i]); } if(isOdd) { odds.push(arr[i]) } } if(odds.length === 0 || evens.length === 0) { return null; } return odds.length < evens.length ? odds[0] : evens[0]; } console.log([ [160, 3, 1719, 19, 11, 13, -21], [4, 8, 15, 16, 24, 42], [16, 6, 40, 66, 68, 28] ].map(findOutlier));
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here's my code:
I believe I could have used filters on the arrays method but just decided to follow the long step.
Here's my code:
I believe I could have used filters on the arrays method but just decided to follow the long step.
Here's my code:
I believe I could have used filters on the arrays method but just decided to follow the long step.