You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

map.js 498B

123456789101112131415161718
  1. const getKeys = require('./get-keys');
  2. const isArrayLike = require('./is-array-like');
  3. const cb = require('./cb');
  4. module.exports = (obj, iteratee, context) => {
  5. iteratee = cb(iteratee, context);
  6. const keys = !isArrayLike(obj) && getKeys(obj);
  7. const { length } = keys || obj;
  8. const results = Array(length);
  9. for (let index = 0; index < length; index++) {
  10. const currentKey = keys ? keys[index] : index;
  11. results[index] = iteratee(obj[currentKey], currentKey, obj);
  12. }
  13. return results;
  14. };