Skip to content

Instantly share code, notes, and snippets.

@tauren
Created March 5, 2014 09:48
Show Gist options
  • Save tauren/9364279 to your computer and use it in GitHub Desktop.
Save tauren/9364279 to your computer and use it in GitHub Desktop.
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