Skip to content

Instantly share code, notes, and snippets.

@ericcornelissen
Last active January 28, 2019 20:09
Show Gist options
  • Select an option

  • Save ericcornelissen/04c62c573814ba9cdec1d6158d2ad676 to your computer and use it in GitHub Desktop.

Select an option

Save ericcornelissen/04c62c573814ba9cdec1d6158d2ad676 to your computer and use it in GitHub Desktop.
Small function to check equality across any number of variables.
/**
* Check equality across any number of variables.
*
* @example <caption>Simple usage</caption>
* var a = 1, b = 1, c = 1, d = 2;
* eql(a, b, c); // returns True
* eql(a, b, c, d); // returns False
*
* @example <caption>Wierd use cases</caption>
* eql("foobar"); // returns True
* eql(); // returns True
*
* @param {...*} arg The arguments to compare.
* @return {boolean} True if all arguments are equal, false otherwise.
* @license The-Unlicense
*/
function eql() {
var base = arguments[0];
for (var i = 1; i < arguments.length; i++) {
if (base !== arguments[i]) return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment