Created
July 6, 2017 18:30
-
-
Save prof3ssorSt3v3/184f901cae6a1f311768da51c22a696c to your computer and use it in GitHub Desktop.
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
//Array some() | |
// Wider availability than includes() | |
// functional approach like map, filter, and forEach | |
// returns Boolean when first positive match is found | |
let movies = ['Star Wars', 'Star Trek', 'Jaws', 'Jurassic Park', 'Gross Pointe Blank', 'Eternal Sunshine of the Spotless Mind', 'Memento', 'Dog Soldiers', 'The Host', 'Gran Torino', 'Close Encounters of the Third Kind', 'Good Will Hunting', 'Layer Cake', 'Casino Royale', 'Almost Famous']; | |
let keyword1 = 'Star'; //appears more than once | |
let keyword2 = 'Cake'; //appears once | |
let keyword3 = 'Max'; //not in list | |
let test1 = movies.some(function(title, index){ | |
console.log(index, title); | |
return title.indexOf(keyword1) > -1 ; | |
}); | |
let test2 = movies.some(function(title, index){ | |
console.log(index, title); | |
return title.indexOf(keyword2) > -1 ; | |
}); | |
let test3 = movies.some(function(title, index){ | |
console.log(index, title); | |
return title.indexOf(keyword3) > -1 ; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment