Pages

Bravo !





Vous avez ecrit en TD, une fonction incroyable, vous pouvez être fier de vous

/**
 *
 * @param {Array} array The array to iterate over
 * @param {Function} transform The function invoked per iteration
 * @returns {Array} Returns The new mapped array.
 */
function map(array, transform) {
  const mapped = [];
  for (let i = 0; i < array.length; i++)
    mapped.push(transform(array[i]));
  return mapped;
}


🥷Voici une bibliothèque qui implémente map https://lodash.com/docs#map

Le code de la fonction est un peu plus compliqué, mais le principe est là ! 

https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6864

🥇On peut découvrir que la fonction peut dans le cas d'un tableau appeler la fonction arrayMap. cette fonction ressemble à notre fonction.


 : https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L1531