Skip to content

Commit

Permalink
add new implementation for combining values
Browse files Browse the repository at this point in the history
  • Loading branch information
elidoran committed Dec 22, 2016
1 parent 50080b6 commit 3082af4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/utils.js
Expand Up @@ -180,5 +180,22 @@ exports.isBuffer = function (obj) {
};

exports.combine = function (a, b) {
return [].concat(a).concat(b);
// we always use both of these, so, let's calculate them now
var firstIsArray = Array.isArray(a);
var secondIsArray = Array.isArray(b);

// mutate `a` to append `b` and then return it
if (firstIsArray) {
secondIsArray ? a.push.apply(a, b) : a.push(b);
return a;
}

// mutate `b` to prepend `a` and then return it
if (secondIsArray) {
b.unshift(a);
return b;
}

// neither are arrays, so, create a new array with both
return [a, b];
};

0 comments on commit 3082af4

Please sign in to comment.