Skip to content

Instantly share code, notes, and snippets.

@aceakash
Created December 20, 2014 10:40
Show Gist options
  • Save aceakash/db7519cbe767b4b986b7 to your computer and use it in GitHub Desktop.
Save aceakash/db7519cbe767b4b986b7 to your computer and use it in GitHub Desktop.
JavaScript recipes
// --------------------------------------------
// You have a value that is either a scalar or an array. You want an array in either case.
function ensureArray(scalarOrArray) {
return [].concat(scalarOrArray);
}
// --------------------------------------------
// You want a clone of an array.
function cloneArray(originalArray) {
return originalArray.slice(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment