Created
February 25, 2015 20:58
-
-
Save bengm/6eb487b3744c4920dd87 to your computer and use it in GitHub Desktop.
JavaScript utility functions
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
function isNumber(val) { | |
return !isNaN(parseFloat(val)) && isFinite(val); | |
} | |
function isDate(val) { | |
return (!isNumber(val)) && (Date.parse(val)) ? true : false; | |
} | |
function isBlank(val) { | |
// returns true for "", null, etc. -- returns false for 0, 1, "a", etc. | |
if (val) { | |
return false; | |
} else { | |
return (val===0) ? false : true | |
} | |
} | |
function uniqueValues(values_array) { | |
var unique = []; | |
$.each(values_array,function(i,e){ | |
if ( (!isBlank(e)) && (unique.indexOf(e) == -1) ) { | |
unique.push(e); | |
} | |
}); | |
return unique; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment