Hollow array

This commit is contained in:
2017-09-17 20:09:12 +02:00
parent 0fc3c79b13
commit 97f6b18ca6

19
hollow-array/index.js Normal file
View File

@@ -0,0 +1,19 @@
// https://www.codewars.com/kata/hollow-array/train/javascript
function isHollow(x) {
do {
if (x.length < 3) return false;
let f = x.shift();
let l = x.pop();
if (f === 0 && l === 0) {
return 0 < x.length && isZeros(x);
}
if (f === 0 || l === 0) {
return false;
}
} while (1);
}
function isZeros(x) {
return x.every(n => n === 0);
}