MCPcopy
hub / github.com/4ian/GDevelop / permutations

Function permutations

newIDE/app/src/EditorFunctions/ApplyEventsChanges.spec.js:668–678  ·  view source on GitHub ↗
(arr: Array<number>)

Source from the content-addressed store, hash-verified

666
667 it('should produce the same result regardless of operation order (mixing single delete, comma-separated delete, insert, and replace)', () => {
668 const permutations = (arr: Array<number>): Array<Array<number>> => {
669 if (arr.length <= 1) return [arr];
670 const result: Array<Array<number>> = [];
671 for (let i = 0; i < arr.length; i++) {
672 const rest = [...arr.slice(0, i), ...arr.slice(i + 1)];
673 for (const perm of permutations(rest)) {
674 result.push([arr[i], ...perm]);
675 }
676 }
677 return result;
678 };
679
680 // 4 operations:
681 // 1. Single delete: delete Comment at index 1

Callers 1

Calls 1

pushMethod · 0.65

Tested by

no test coverage detected