Skip to content

Instantly share code, notes, and snippets.

@c01nd01r
Last active April 9, 2016 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c01nd01r/6a82f0d5687115817789 to your computer and use it in GitHub Desktop.
Save c01nd01r/6a82f0d5687115817789 to your computer and use it in GitHub Desktop.
Глубокий поиск / 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment