Created
December 20, 2014 10:40
-
-
Save aceakash/db7519cbe767b4b986b7 to your computer and use it in GitHub Desktop.
JavaScript recipes
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
// -------------------------------------------- | |
// 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