From 3c47f6b85d3d101121d48ad63b1673cf9faf6c56 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 5 Jan 2023 05:43:01 +0300 Subject: [PATCH] rewrote arrayCmp(..)... Signed-off-by: Alex A. Naanou --- package.json | 2 +- test.js | 32 +++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 073b4bd..55c7cb6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-test", - "version": "1.5.7", + "version": "1.5.8", "description": "experimental test runner....", "main": "test.js", "bin": { diff --git a/test.js b/test.js index 236dfc8..5bb1137 100644 --- a/test.js +++ b/test.js @@ -105,17 +105,27 @@ function(){ // compare two arrays by items... // XXX this is defined in object.js/test.js and here, need to chose one... -var arrayCmp = function(a, b){ - var ka = Object.keys(a) - var kb = Object.keys(b) - return a === b - || (a.length == b.length - && ka - // keep only non matching stuff... - .filter(function(k){ - return a[k] !== b[k] - && a[k] != b[k] }) - .length == 0) } +var arrayCmp = +module.arrayCmp = +function(a, b){ + if(a === b){ + return true } + if(a.length != b.length){ + return false } + // check elements... + for(var [i, e] of Object.entries(a)){ + // XXX not sure how strict should we be here??? + //if(typeof(e) !== typeof(b[i])){ + if(e.constructor !== b[i].constructor){ + return false } + if(e instanceof Array){ + if(arrayCmp(e, b[i])){ + continue } + return false } + if(e !== b[i] + && e != b[i]){ + return false } } + return true } // Assert constructor...