diff --git a/lib/discrepances.js b/lib/discrepances.js index 42bec64..399589b 100644 --- a/lib/discrepances.js +++ b/lib/discrepances.js @@ -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]}; diff --git a/test/test.js b/test/test.js index 7d5b876..71d5bff 100644 --- a/test/test.js +++ b/test/test.js @@ -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)} }},