Skip to content

Instantly share code, notes, and snippets.

@marlun78
Last active February 10, 2017 08:39
Show Gist options
  • Save marlun78/885eb0021e980c6ce0fb to your computer and use it in GitHub Desktop.
Save marlun78/885eb0021e980c6ce0fb to your computer and use it in GitHub Desktop.
Number.isFinite polyfill
/**
* Number.isFinite
* Copyright (c) 2014 marlun78
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83
*
* Spec: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isfinite
*/
if (typeof Number.isFinite !== 'function') {
Number.isFinite = function isFinite(value) {
// 1. If Type(number) is not Number, return false.
if (typeof value !== 'number') {
return false;
}
// 2. If number is NaN, +∞, or −∞, return false.
if (value !== value || value === Infinity || value === -Infinity) {
return false;
}
// 3. Otherwise, return true.
return true;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment