index.js 455 B

1234567891011121314151617181920212223
  1. /*!
  2. * arr-map <https://github.com/jonschlinkert/arr-map>
  3. *
  4. * Copyright (c) 2015, 2017, Jon Schlinkert.
  5. * Released under the MIT License.
  6. */
  7. 'use strict';
  8. var iterator = require('make-iterator');
  9. module.exports = function map(arr, fn, thisArg) {
  10. if (arr == null) return [];
  11. fn = iterator(fn, thisArg);
  12. var len = arr.length;
  13. var res = new Array(len);
  14. for (var i = 0; i < len; i++) {
  15. res[i] = fn(arr[i], i, arr);
  16. }
  17. return res;
  18. };