-
Notifications
You must be signed in to change notification settings - Fork 0
/
kata.js
30 lines (24 loc) · 932 Bytes
/
kata.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// #1
// function oddOrEven(array) {
// return array.length === 0 ||
// array.reduce((acc, i) => acc + i) % 2 === 0 ? 'even' : 'odd'
// }
// #2
function oddOrEven(array) {
return array.reduce((acc, i) => acc + i, 0) % 2 ? 'odd' : 'even';
}
console.log(oddOrEven([0])); // 'even'
console.log(oddOrEven([1])); // 'odd'
console.log(oddOrEven([])); // 'even'
console.log(oddOrEven([0, 1, 5])); // 'even'
console.log(oddOrEven([0, 1, 3])); // 'even'
console.log(oddOrEven([1023, 1, 2])); // 'even'
console.log(oddOrEven([0, -1, -5])); // 'even'
console.log(oddOrEven([0, -1, -3])); // 'even'
console.log(oddOrEven([-1023, 1, -2])); // 'even'
console.log(oddOrEven([0, 1, 2])); // 'odd'
console.log(oddOrEven([0, 1, 4])); // 'odd'
console.log(oddOrEven([1023, 1, 3])); // 'odd'
console.log(oddOrEven([0, -1, 2])); // 'odd'
console.log(oddOrEven([0, 1, -4])); // 'odd'
console.log(oddOrEven([-1023, -1, 3])); // 'odd'