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

Corrected tests in levels 4, 28, 41 (sorting errors) #3

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,7 @@ var generators = {
'4': function (inbox) {
// Output each pair with the items sorted in reverse order
return splitGroups(inbox, 2).reduce(function (outbox, pair) {
return outbox.concat(pair.sort(function (a, b) {
return a === b
? 0
: a < b
? 1
: -1;
}));
return outbox.concat([ pair[1], pair[0] ]);
}, []);
},
/*** Coffee Time ***/
Expand Down Expand Up @@ -233,7 +227,9 @@ var generators = {
'28': function (inbox) {
// For each triple, sort then output
return splitGroups(inbox, 3).reduce(function (outbox, triplet) {
return outbox.concat(triplet.sort());
return outbox.concat(Number.isInteger(triplet[0]) ?
triplet.sort(function(a,b){ return a - b; }) :
triplet.sort() );
}, []);
},
/*** Storage Floor ***/
Expand Down Expand Up @@ -349,15 +345,15 @@ var generators = {
// Split strings, sort items in each string, then output all strings
return splitStrings(inbox)
.map(function (string) {
// This assumes that the string is uniform in the type of its
// elements. Which should be true in any case
// This assumes that the string is uniform in the type of its
// elements. Which should be true in any case
return string.sort(function (a, b) {
if (typeof a == 'number') {
return a - b;
} else {
return a < b ? -1 : (a > b ? 1 : 0);
}
});
if (typeof a == 'number') {
return a - b;
} else {
return a < b ? -1 : (a > b ? 1 : 0);
}
});
})
.reduce(function (output, string) {
return output.concat(string);
Expand Down