← Back to challenges

Lonely Integer

JavaScriptHardnumbersarraysfunctional_programming

Instructions

You are given an array of integers having both negative and positive values, except for one integer which can be negative or positive. Create a function to find out that integer.

Examples

lonelyInteger([1, -1, 2, -2, 3]) ➞ 3
// 3 has no matching negative appearance.

lonelyInteger([-3, 1, 2, 3, -1, -4, -2]) ➞ -4
// -4 has no matching positive appearance.

lonelyInteger([-9, -105, -9, -9, -9, -9, 105]) ➞ -9

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Return the Middle Character(s) of a String