From 789479b2c21342216b4a6ff7c370b1c36d5730f9 Mon Sep 17 00:00:00 2001 From: "Diego F.(EW7)" Date: Tue, 4 Oct 2016 09:28:34 -0300 Subject: [PATCH] null/number --- lib/discrepances.js | 9 +++++++-- test/test.js | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) 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)} }},