Skip to content

Lab/critical routers #50

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

Merged
merged 16 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
new exercise
  • Loading branch information
amejiarosario committed Apr 25, 2020
commit a678c0edb088066a4460e94fe2beda0de3d8801e
14 changes: 14 additions & 0 deletions lab/exercises/10-mixed/even-first.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function evenFirst(array) {
let lo = 0;
let hi = 1;
while (hi < array.length) {
if (array[hi] % 2 === 0) {
[array[hi], array[lo]] = [array[lo], array[hi]];
lo++;
}
hi++;
}
return array;
}

module.exports = evenFirst;
9 changes: 9 additions & 0 deletions lab/exercises/10-mixed/even-first.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const fn = require('./even-first');

describe('Sort even first and then odd', () => {
it('should work', () => {
const actual = fn([5, 4, 3, 7, 8, 3, 2]);
expect(actual.slice(0, 3)).toEqual(expect.arrayContaining([4, 8, 2]));
expect(actual.slice(3)).toEqual(expect.arrayContaining([5, 3, 7, 3]));
});
});