diff --git a/lib/helper.js b/lib/helper.js index 8e5727d..cdf598a 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -13,16 +13,16 @@ helper.isDir = function isDir (dir) { // Create a `key:[]` if doesnt exist on `obj` then push or concat the `val` helper.objectPush = function objectPush (obj, key, val) { - if (obj[key] == null) { - obj[key] = []; + var arr = obj[key]; + if (arr == null) { + obj[key] = arr = []; } if (Array.isArray(val)) { - obj[key] = obj[key].concat(val); - } else if (val) { - obj[key].push(val); + obj[key] = arr = helper.unique(arr, val); + } else if (val && arr.indexOf(val) === -1) { + arr.push(val); } - obj[key] = helper.unique(obj[key]); - return obj[key]; + return arr; }; // Ensures the dir is marked with path.sep