Skip to content

Commit

Permalink
null/number
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoefe committed Oct 4, 2016
1 parent 20bf7d8 commit 789479b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/discrepances.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@
var discrepances = {};
/*jshint +W004 */

function getType(variable) {
if(null === variable) { return 'null'; }
return typeof variable;
}

discrepances = function discrepances(a, b){
if(a === b){
return null;
}
var typeA = typeof a;
var typeB = typeof b;
var typeA = getType(a);
var typeB = getType(b);
if(typeA === typeB) {
if(typeA === 'number') {
return {difference:a-b, values:[a,b]};
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("discrepances", function(){
{a:4 , b:4 , expected: null },
{a:4 , b:5 , expected: {difference:-1 , values:[4, 5] }},
{a:"4" , b:4 , expected: {types:['string', 'number'], values:["4", 4] }},
{skip:true, a:null , b:0 , expected: {types:['null' , 'number'], values:[null, 0] }},
{a:null , b:0 , expected: {types:['null' , 'number'], values:[null, 0] }},
{skip:true, a:new Date() , b:/a/ , expected: {class:['Date' , 'RegExp'], values:[new Date(), /a/] }},
{skip:true, a:new Date(2011,1,3), b:new Date(2011,1,4) , expected: {difference:'a definir', values:[new Date(2011,1,3), new Date(2011,1,4)] }},
{skip:true, a:[1,2,3,4,5] , b:[1,2,33,4,5,6] , expected: {array:{length:discrepances(5,6), 2:discrepances(3,33)} }},
Expand Down

0 comments on commit 789479b

Please sign in to comment.