Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created July 6, 2017 18:30
Show Gist options
  • Save prof3ssorSt3v3/184f901cae6a1f311768da51c22a696c to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/184f901cae6a1f311768da51c22a696c to your computer and use it in GitHub Desktop.
//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