Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace concat with spread: items can be arrays #527

Merged
merged 1 commit into from
Jan 2, 2023

Conversation

ChristopherChudzicki
Copy link
Contributor

Fixes #526

@@ -28,7 +28,7 @@ function permutations(arr) {
for (var j = 0, len2 = partial.length; j <= len2; j++) {
var start = partial.slice(0, j);
var end = partial.slice(j);
var merged = start.concat(first, end);
var merged = start.concat([first], end);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"first" is an item of the array being permuted. So if arr has type T[], then:

arr: T[]
first: T
start: T[]
end: T[]

The arguments to concat should both be of type T[].

The fact that this was (mostly) working before is due to JS's concat behaving somewhat like push: it can accept non-array values. But if T itself is an array type, then this did not work as intended.

@angus-c
Copy link
Owner

angus-c commented Jan 2, 2023

Thanks great catch!

@angus-c angus-c merged commit 90e1ef2 into angus-c:master Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Permutations gives incorrect result for arrays of arrays
2 participants