Skip to content

Instantly share code, notes, and snippets.

@Shelob9 Shelob9/1.js
Created Nov 30, 2018

Embed
What would you like to do?
function addTwoNumbers(numberOne, numberTwo){}
describe( 'Adding two number', () => {
it( 'works with postive numbers', () => {
expect( addTwoNumbers(1,2) ).toBe(3);
});
it( 'works with a negative number', () =>{
expect( addTwoNumbers(-1,2) ).toBe(1);
});
});
function addTwoNumbers(numberOne, numberTwo){
return numberOne + numberTwo;
}
describe( 'Adding two number', () => {
it( 'works with postive numbers', () => {
expect( addTwoNumbers(1,2) ).toBe(3);
});
it( 'works with a negative number', () =>{
expect( addTwoNumbers(-1,2) ).toBe(1);
});
it( 'rounds when rounding argument is passed', () => {
expect( addTwoNumbers( 1, 2.555555, 2 ) ).toBe( 3.55 );
});
it( 'Does not round by default', () => {
expect( addTwoNumbers( 1, 2.555555 ) ).toBe( 3.555555 );
});
});
function addTwoNumbers(numberOne, numberTwo, precision = null ){
let sum = numberOne + numberTwo;
if( precision ){
sum = Number.parseFloat(sum).precision(4);
}
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.