map.js 573 B

123456789101112131415161718
  1. define(['./_cb', './_isArrayLike', './keys'], function (_cb, _isArrayLike, keys) {
  2. // Return the results of applying the iteratee to each element.
  3. function map(obj, iteratee, context) {
  4. iteratee = _cb(iteratee, context);
  5. var _keys = !_isArrayLike(obj) && keys(obj),
  6. length = (_keys || obj).length,
  7. results = Array(length);
  8. for (var index = 0; index < length; index++) {
  9. var currentKey = _keys ? _keys[index] : index;
  10. results[index] = iteratee(obj[currentKey], currentKey, obj);
  11. }
  12. return results;
  13. }
  14. return map;
  15. });