Skip to content

Instantly share code, notes, and snippets.

@Announcement
Created August 20, 2018 10:12
Show Gist options
  • Save Announcement/a4601a2bc137d68fc7f1671bc4f73de6 to your computer and use it in GitHub Desktop.
Save Announcement/a4601a2bc137d68fc7f1671bc4f73de6 to your computer and use it in GitHub Desktop.
any performance enhancements greatly appreciated
function * reorder (current, bucket) {
if (bucket.length === 0) yield current;
else if (bucket.length === 1) yield current.concat(bucket)
else if (bucket.length > 1)
for (let i = 0; i < bucket.length; i++) {
yield* reorder([...current, bucket[i]], [...bucket.slice(0, i), ...bucket.slice(i + 1)])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment