Skip to content

Instantly share code, notes, and snippets.

@bengm
Created February 25, 2015 20:58
Show Gist options
  • Save bengm/6eb487b3744c4920dd87 to your computer and use it in GitHub Desktop.
Save bengm/6eb487b3744c4920dd87 to your computer and use it in GitHub Desktop.
JavaScript utility functions
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