function neg(number) { return typeof number === "number"?-number:NaN; }
- function neg(number) {
return -(number);- return typeof number === "number"?-number:NaN;
- }
// TODO: Add your tests here // Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework. // [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework) // are still available for now. // // For new tests, using [Chai](https://chaijs.com/) is recommended. // You can use it by requiring: Test.assertEquals(neg(1), -1) Test.assertSimilar(neg([2]), NaN)
- // TODO: Add your tests here
- // Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.
- // [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)
- // are still available for now.
- //
- // For new tests, using [Chai](https://chaijs.com/) is recommended.
- // You can use it by requiring:
Test.assertEquals(neg(1), -1,)- Test.assertEquals(neg(1), -1)
- Test.assertSimilar(neg([2]), NaN)
Object.is(NaN,NaN) === true;
Sometimes we buy something we may receive some change, so, how much?
#Examples:
getChange(4,10) => 6
getChange(4,100) => 96;
getChange(4.5,100) => 95.5;
getChange(3.5,5) => 1.5;
getChange(3.8,5) => 1.2;
###1 note this:youMoney > allPrice.
###2 Subtraction is not necessarily correct.
###3 Maybe you can use Math.
function getChange(allPrice,youMoney){
return Math.round(youMoney*1000 - allPrice*1000)/1000;
}
describe("Solution", function() {
it("should test for something", function() {
Test.assertEquals(getChange(4,10), 6);
Test.assertEquals(getChange(4,100), 96);
Test.assertEquals(getChange(4.5,100), 95.5);
Test.assertEquals(getChange(3.5,5), 1.5);
Test.assertEquals(getChange(3.8,5), 1.2);
// assert.strictEqual(1 + 1, 2);
});
});