map.js 699 B

1234567891011121314151617181920212223
  1. var isObject = require('../lang/isObject');
  2. var values = require('../object/values');
  3. var arrMap = require('../array/map');
  4. var makeIterator = require('../function/makeIterator_');
  5. /**
  6. * Map collection values, returns Array.
  7. */
  8. function map(list, callback, thisObj) {
  9. callback = makeIterator(callback, thisObj);
  10. // list.length to check array-like object, if not array-like
  11. // we simply map all the object values
  12. if( isObject(list) && list.length == null ){
  13. list = values(list);
  14. }
  15. return arrMap(list, function (val, key, list) {
  16. return callback(val, key, list);
  17. });
  18. }
  19. module.exports = map;