Skip to content

Commit 0689f73

Browse files
committed
Find the parity outlier
1 parent 2a0aec1 commit 0689f73

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

FindParityOutlier.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
//You are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer (N). Write a method that takes the array as an argument and returns this "outlier" (N).
3+
4+
function findOutlier(integers){
5+
var amoutEven = 0
6+
var amoutOdd = 0
7+
if(Math.abs(integers[0] % 2) == 0) {
8+
amoutEven++
9+
} else {
10+
amoutOdd++
11+
}
12+
13+
if(Math.abs(integers[1] % 2) == 0) {
14+
amoutEven++
15+
} else {
16+
amoutOdd++
17+
}
18+
19+
if(Math.abs(integers[2] % 2) == 0) {
20+
amoutEven++
21+
} else {
22+
amoutOdd++
23+
}
24+
25+
var isEvenArray = amoutEven > amoutOdd
26+
27+
28+
for (const integer of integers){
29+
const resto = Math.abs(integer % 2)
30+
31+
if (isEvenArray && resto == 1){
32+
return integer
33+
} else if (!isEvenArray && resto == 0){
34+
return integer
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)