composeArgsRight.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /* Native method references for those with the same name as other `lodash` methods. */
  2. var nativeMax = Math.max;
  3. /**
  4. * This function is like `composeArgs` except that the arguments composition
  5. * is tailored for `_.partialRight`.
  6. *
  7. * @private
  8. * @param {Array|Object} args The provided arguments.
  9. * @param {Array} partials The arguments to append to those provided.
  10. * @param {Array} holders The `partials` placeholder indexes.
  11. * @returns {Array} Returns the new array of composed arguments.
  12. */
  13. function composeArgsRight(args, partials, holders) {
  14. var holdersIndex = -1,
  15. holdersLength = holders.length,
  16. argsIndex = -1,
  17. argsLength = nativeMax(args.length - holdersLength, 0),
  18. rightIndex = -1,
  19. rightLength = partials.length,
  20. result = Array(argsLength + rightLength);
  21. while (++argsIndex < argsLength) {
  22. result[argsIndex] = args[argsIndex];
  23. }
  24. var offset = argsIndex;
  25. while (++rightIndex < rightLength) {
  26. result[offset + rightIndex] = partials[rightIndex];
  27. }
  28. while (++holdersIndex < holdersLength) {
  29. result[offset + holders[holdersIndex]] = args[argsIndex++];
  30. }
  31. return result;
  32. }
  33. module.exports = composeArgsRight;