Last active
April 9, 2016 10:13
-
-
Save c01nd01r/6a82f0d5687115817789 to your computer and use it in GitHub Desktop.
Глубокий поиск / BasicQual#1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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