Skip to content

Instantly share code, notes, and snippets.

@basekays
Created October 20, 2016 02:43
Show Gist options
  • Select an option

  • Save basekays/24d3966935736adf99514372a1be24b4 to your computer and use it in GitHub Desktop.

Select an option

Save basekays/24d3966935736adf99514372a1be24b4 to your computer and use it in GitHub Desktop.
var _ = {};
_.every = function(list, condition) {
for (var i = 0; i<list.length; i++) {
if (!condition(list[i])) {
return false;
}
}
return true;
}
@amy-chiu

amy-chiu commented Oct 29, 2016

Copy link
Copy Markdown

very close! condition(list[i]) could evaluate to true. and the bang would make it false. so you're just making it the opposite of what it really evaluates to. so if condition(list[i]) is false, you want to return false. so it would look something like:

_.every = function(list, condition) {
  for (var i = 0; i<list.length; i++) {
    if (condition(list[i]) === false) {
      return false;
    }
  }
  return true;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment