3 var util = require('util');
4 var visit = require('object-visit');
7 * Map `visit` over an array of objects.
9 * @param {Object} `collection` The context in which to invoke `method`
10 * @param {String} `method` Name of the method to call on `collection`
11 * @param {Object} `arr` Array of objects.
14 module.exports = function mapVisit(collection, method, val) {
16 return visit.apply(null, arguments);
19 if (!Array.isArray(val)) {
20 throw new TypeError('expected an array: ' + util.inspect(val));
23 var args = [].slice.call(arguments, 3);
25 for (var i = 0; i < val.length; i++) {
28 visit.apply(null, [collection, method, ele].concat(args));
30 collection[method].apply(collection, [ele].concat(args));
35 function isObject(val) {
36 return val && (typeof val === 'function' || (!Array.isArray(val) && typeof val === 'object'));