source: node_modules/es-toolkit/dist/compat/function/rearg.mjs

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 441 bytes
Line 
1import { flatten } from '../array/flatten.mjs';
2
3function rearg(func, ...indices) {
4 const flattenIndices = flatten(indices);
5 return function (...args) {
6 const reorderedArgs = flattenIndices.map(i => args[i]).slice(0, args.length);
7 for (let i = reorderedArgs.length; i < args.length; i++) {
8 reorderedArgs.push(args[i]);
9 }
10 return func.apply(this, reorderedArgs);
11 };
12}
13
14export { rearg };
Note: See TracBrowser for help on using the repository browser.