/** * Get fn wrapped with array/object attrs recognition * * @return {Function} Target function */ 'use strict'; module.exports = function(fn){ return function (a) { var args = arguments; if (a instanceof Array) { var result = new Array(a.length), slice; for (var i = 0; i < a.length; i++){ slice = []; for (var j = 0, l = args.length, val; j < l; j++){ val = args[j] instanceof Array ? args[j][i] : args[j]; slice.push(val); } result[i] = fn.apply(this, slice); } return result; } else if (typeof a === 'object') { var result = {}, slice; for (var i in a){ slice = []; for (var j = 0, l = args.length, val; j < l; j++){ val = typeof args[j] === 'object' ? args[j][i] : args[j]; slice.push(val); } result[i] = fn.apply(this, slice); } return result; } else { return fn.apply(this, args); } }; };