Created
January 19, 2017 11:40
-
-
Save phizaz/05349c98fd350a016f41e7388f0c0d68 to your computer and use it in GitHub Desktop.
Javascript Utils
This file contains hidden or 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
/** | |
* returns true iff val equals every element in the list | |
*/ | |
function all(list, val) { | |
if (list.length === 0) return false | |
const first = list[0] | |
if (first !== val) return false | |
for (const elem of list) { | |
if (first !== elem) return false | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment