Created
March 5, 2014 09:48
-
-
Save tauren/9364279 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 _ = require('lodash'); | |
/** | |
* Make sure to always return an array. If an array is passed, then | |
* return the array. If passed a string, return an array containing | |
* that string. If passed undefined or null, return an empty array. | |
* | |
* @param [String|Array] values A string or an array | |
* @return [Array] | |
*/ | |
function makeArray(values) { | |
// return empty array if values is empty | |
if (_.isUndefined(values) || _.isNull(values) ) { | |
return []; | |
} | |
// return array of values, converting to array if necessary | |
return !_.isArray(values) ? [values] : values; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment