Skip to content

Instantly share code, notes, and snippets.

@karenpeng
Last active August 29, 2015 14:19
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 karenpeng/9fe4559cee213455d791 to your computer and use it in GitHub Desktop.
Save karenpeng/9fe4559cee213455d791 to your computer and use it in GitHub Desktop.
var test = [1,2,3]
function check(arr){
arr.forEach(function(el){
if(el === 2){
console.log('ouch')
return true;
}
})
return false;
}
function check1(arr){
for(var i = 0; i < arr.length; i++){
if(arr[i] === 2)return true;
}
return false;
}
check(test) //ouch false
check1(test) // true
//one more layer needs to be return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment