blob: 426735d9f51e4bdd4e34c8675d3ec134981c6c84 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  | 
'use strict';
var utils = require('./utils');
/**
 * Map `visit` over an array of objects.
 *
 * @param  {Object} `collection` The context in which to invoke `method`
 * @param  {String} `method` Name of the method to call on `collection`
 * @param  {Object} `arr` Array of objects.
 */
module.exports = function mapVisit(collection, method, arr) {
  if (!Array.isArray(arr)) {
    throw new TypeError('expected an array');
  }
  arr.forEach(function(val) {
    if (typeof val === 'string') {
      collection[method](val);
    } else {
      utils.visit(collection, method, val);
    }
  });
};
 
  |