map.js 464 B

12345678910111213141516171819202122
  1. var makeIterator = require('../function/makeIterator_');
  2. /**
  3. * Array map
  4. */
  5. function map(arr, callback, thisObj) {
  6. callback = makeIterator(callback, thisObj);
  7. var results = [];
  8. if (arr == null){
  9. return results;
  10. }
  11. var i = -1, len = arr.length;
  12. while (++i < len) {
  13. results[i] = callback(arr[i], i, arr);
  14. }
  15. return results;
  16. }
  17. module.exports = map;