composeArgs.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. /* Native method references for those with the same name as other `lodash` methods. */
  2. var nativeMax = Math.max;
  3. /**
  4. * Creates an array that is the composition of partially applied arguments,
  5. * placeholders, and provided arguments into a single array of arguments.
  6. *
  7. * @private
  8. * @param {Array|Object} args The provided arguments.
  9. * @param {Array} partials The arguments to prepend to those provided.
  10. * @param {Array} holders The `partials` placeholder indexes.
  11. * @returns {Array} Returns the new array of composed arguments.
  12. */
  13. function composeArgs(args, partials, holders) {
  14. var holdersLength = holders.length,
  15. argsIndex = -1,
  16. argsLength = nativeMax(args.length - holdersLength, 0),
  17. leftIndex = -1,
  18. leftLength = partials.length,
  19. result = Array(leftLength + argsLength);
  20. while (++leftIndex < leftLength) {
  21. result[leftIndex] = partials[leftIndex];
  22. }
  23. while (++argsIndex < holdersLength) {
  24. result[holders[argsIndex]] = args[argsIndex];
  25. }
  26. while (argsLength--) {
  27. result[leftIndex++] = args[argsIndex++];
  28. }
  29. return result;
  30. }
  31. module.exports = composeArgs;