Created
August 14, 2019 12:33
-
-
Save gatarelib/4624d52c1f88424b83ef0dc27d6e803b to your computer and use it in GitHub Desktop.
Andela assessment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mySort(nums) { | |
let evens = []; | |
let odds = []; | |
for (let i = 0; i < nums.length; i++) { | |
if(typeof nums[i] === "number"){ | |
if ((nums[i] % 2) === 1) { | |
odds.push(parseInt(nums[i])); | |
} | |
else { | |
evens.push(parseInt(nums[i])); | |
} | |
} | |
} | |
let numsArray = odds.sort((a, b) => a - b).concat(evens.sort((a, b) => a - b)); | |
return numsArray; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let assert = require("chai").assert; | |
describe("Algorithms", () => { | |
describe("mySort( [2,1] )", () => { | |
let result = mySort( [2,1] ); | |
it("Should return an Array", () => { | |
assert.typeOf(result.push, "function"); | |
}); | |
}) | |
describe("mySort( [90, 45, 66] )", function(){ | |
let result = mySort( [90, 45, 66] ); | |
it("[90, 45, 66] should return [45, 66, 90]", () => { | |
assert.deepEqual(result, [45, 66, 90]); | |
}); | |
}); | |
describe("mySort( [90, 45, 66] )", function(){ | |
let result = mySort( [90, 45, 66, 'bye', 100.5] ); | |
it("[90, 45, 66, 'bye', 100.5] should ignore random strings, treat input as integers, and return [45, 66, 90, 100]", () => { | |
assert.deepEqual(result, [45, 66, 90, 100]); | |
}); | |
}); | |
describe("mySort( [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] )", function(){ | |
let result = mySort( [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ); | |
it("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] should return [1, 3, 5, 7, 9, 2, 4, 6, 8]", () => { | |
assert.deepEqual(result, [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment