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.

41 lines
1.4 KiB

4 years ago
  1. /* Built-in 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} args The provided arguments.
  9. * @param {Array} partials The arguments to append to those provided.
  10. * @param {Array} holders The `partials` placeholder indexes.
  11. * @params {boolean} [isCurried] Specify composing for a curried function.
  12. * @returns {Array} Returns the new array of composed arguments.
  13. */
  14. function composeArgsRight(args, partials, holders, isCurried) {
  15. var argsIndex = -1,
  16. argsLength = args.length,
  17. holdersIndex = -1,
  18. holdersLength = holders.length,
  19. rightIndex = -1,
  20. rightLength = partials.length,
  21. rangeLength = nativeMax(argsLength - holdersLength, 0),
  22. result = Array(rangeLength + rightLength),
  23. isUncurried = !isCurried;
  24. while (++argsIndex < rangeLength) {
  25. result[argsIndex] = args[argsIndex];
  26. }
  27. var offset = argsIndex;
  28. while (++rightIndex < rightLength) {
  29. result[offset + rightIndex] = partials[rightIndex];
  30. }
  31. while (++holdersIndex < holdersLength) {
  32. if (isUncurried || argsIndex < argsLength) {
  33. result[offset + holders[holdersIndex]] = args[argsIndex++];
  34. }
  35. }
  36. return result;
  37. }
  38. module.exports = composeArgsRight;