Last active
December 18, 2015 00:09
-
-
Save kentcdodds/5694667 to your computer and use it in GitHub Desktop.
Utility functions. Simple functions I don't want to forget.
This file contains 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
var capitaliseFirstLetter = function(string) { | |
return string.charAt(0).toUpperCase() + string.slice(1); | |
}; | |
/* | |
* Detect IE. From http://stackoverflow.com/a/16657946 | |
* ---------------------------------------------------------- | |
* If you're not in IE (or IE version is less than 5) then: | |
* ie === undefined | |
* If you're in IE (>=5) then you can determine which version: | |
* ie === 7; // IE7 | |
* Thus, to detect IE: | |
* if (ie) {} | |
* And to detect the version: | |
* ie === 6 // IE6 | |
* ie > 7 // IE8, IE9, IE10 ... | |
* ie < 9 // Anything less than IE9 | |
* ---------------------------------------------------------- | |
*/ | |
var ie = (function() { | |
var undef; | |
var rv = -1; // Return value assumes failure. | |
if (navigator.appName == 'Microsoft Internet Explorer') { | |
var ua = navigator.userAgent; | |
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); | |
if (re.exec(ua) != null) { | |
rv = parseFloat( RegExp.$1 ); | |
} | |
} | |
return ((rv > -1) ? rv : undef); | |
}()); | |
var randomNumber = function(low, high) { | |
return Math.floor(Math.random() * high) + low; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment