Глубокий поиск / BasicQual#1
function deepSearch(array, number) {
if (Array.isArray(array)){
return array.some(function search(value) {
if (value === number) {
return true;
} else if (Array.isArray(value)) {
return value.some(search);
} else {
return false;
}
});
} else {
console.log(array +' is not array!');
return false;
}
}
console.log(deepSearch([1, 2, 3, 4, 5], 3));
//true
console.log(deepSearch([1, 2, 3, 4, 5], 8));
//false
console.log(deepSearch([1, 2, 4, 9, [3, 7, [22, [23]], 4, 5], 17], 8));
//false
console.log(deepSearch([1, 2, [3, 7, [22, [23]], 4, 5], 17], 7));
//true
console.log(deepSearch(2, 7));
//false