Test name | Executions per second |
---|---|
String arrays not equivalent | 13414605.0 Ops/sec |
String arrays equivalent but not same order | 3693158.0 Ops/sec |
String arrays equivalent same order | 3857729.2 Ops/sec |
Number arrays not equivalent | 651129.5 Ops/sec |
Number arrays equivalent not same order | 982396.9 Ops/sec |
Number arrays equivalent same order | 1037951.9 Ops/sec |
Object arrays not equivalent | 2791486.2 Ops/sec |
Object arrays equivalent not same order | 573312.2 Ops/sec |
Object arrays equivalent same order | 10417133.0 Ops/sec |
String arrays not equivalent (_) | 624249.2 Ops/sec |
String arrays equivalent but not same order (_) | 492459.5 Ops/sec |
String arrays equivalent same order (_) | 498759.2 Ops/sec |
Number arrays not equivalent (_) | 100876.0 Ops/sec |
Number arrays equivalent not same order (_) | 118200.0 Ops/sec |
Number arrays equivalent same order (_) | 118380.7 Ops/sec |
Object arrays not equivalent (_) | 429934.8 Ops/sec |
Object arrays equivalent not same order (_) | 212108.5 Ops/sec |
Object arrays equivalent same order (_) | 241821.2 Ops/sec |
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
function equivalent(arr1, arr2) {
if (arr1.length !== arr2.length) {
return false
}
arr1.forEach((elem) => {
const index = arr2.findIndex((elem2) => elem === elem2)
if (index === -1) { // not found
return false
}
arr2.splice(index, 1) // remove element
})
if (arr2.length > 0) { // if still values in arr2, they are not in arr1
return false
}
return true
}
function _equiv(arr1,arr2) { return _.isEqual(_.sortBy(arr1), _.sortBy(arr2)) }
const arr1 = ['a', 'b', 'c', 'd']
const arr2 = ['b', 'a', 'd']
equivalent(arr1, arr2)
const arr1 = [{ KMFGNHeL: 0.2033444758693359,
HJMzVLhZ: 373,
WeKLrVwh: 'BlgvHn',
hutdufbF: 'dfalRd',
XqrwJjnR: null }, { xSUdtASV: 'ejVI',
pgUHOMNn: true,
dhQPzxuj: false,
MHUchilq: 719,
TWHkCOOT: 0.46691745627158165 }]
const arr2 = [{ fZhKYyQT: 379,
WtnguXmc: 64,
VaodnYbC: 0.7490618732830732,
hGhDbXmd:
{ pQnhfhKR: 0.029586390538915097,
oSpBStGM:
{ dKoUrTyg: 0.8023980228055398,
RMSlVEQw: null,
KiPTRmIf: 'GIfgX',
OOpGOzXD: null,
YSTcLKDa: 777 },
eDsjVaPK: null,
LrqwYwJs: 0.4117401997875565,
AbIoXBix: 'THmFh' },
anQZVYxA: 0.8284963046084715 }]
_equiv(arr1, arr2)
const arr1 = [54 ,34 ,16 ,100 ,64 ,19 ,88 ,93 ,43 ,58 ,44 ,83 ,98 ,72 ,88 ,4 ,93 ,2 ,23 ,95]
const arr2 = [54 ,34 ,16 ,100 ,64 ,19 ,88 ,93 ,43 ,58 ,44 ,83 ,98 ,72 ,88 ,4 ,93 ,2 ,23 ,95]
_equiv(arr1, arr2)
const arr1 = [54 ,34 ,16 ,100 ,64 ,19 ,88 ,93 ,43 ,58 ,44 ,83 ,98 ,72 ,88 ,4 ,93 ,2 ,23 ,95]
const arr2 = [54 ,34 ,64 ,100 ,16 ,19 ,88 ,43 ,93 ,58 ,44 ,83 ,88 ,72 ,98 ,4 ,93 ,2 ,23 ,95]
_equiv(arr1, arr2)
const arr1 = [54 ,34 ,16 ,100 ,64 ,19 ,88 ,93 ,43 ,58 ,44 ,83 ,98 ,72 ,88 ,4 ,93 ,2 ,23 ,95]
const arr2 = [79 ,12 ,38 ,68 ,6 ,40 ,67 ,93 ,98 ,48 ,64 ,45 ,33 ,6 ,73 ,43 ,7 ,57 ,10 ,77]
_equiv(arr1, arr2)
const arr1 = ['a', 'b', 'c', 'd']
const arr2 = ['a', 'b', 'c', 'd']
_equiv(arr1, arr2)
const arr1 = ['a', 'b', 'c', 'd']
const arr2 = ['b', 'a', 'd', 'c']
_equiv(arr1, arr2)
const arr1 = ['a', 'b', 'c', 'd']
const arr2 = ['b', 'a', 'd']
_equiv(arr1, arr2)
const arr1 = [{ TXzgcBbd: true,
SKxzRzNW: 0.9618236935424078,
CNLZbZcn: 286,
OsmfcuUG: 0.5933390334187918,
APBdqQZT: 697 }, { TXzgcBbd: true,
SKxzRzNW: 0.9618236935424078,
CNLZbZcn: 286,
OsmfcuUG: 0.5933390334187918,
APBdqQZT: 697 }]
const arr2 = [{ TXzgcBbd: true,
SKxzRzNW: 0.9618236935424078,
CNLZbZcn: 286,
OsmfcuUG: 0.5933390334187918,
APBdqQZT: 697 }, { TXzgcBbd: true,
SKxzRzNW: 0.9618236935424078,
CNLZbZcn: 286,
OsmfcuUG: 0.5933390334187918,
APBdqQZT: 697 }]
equivalent(arr1, arr2)
const arr1 = [{
"DnBoOgED":{
"ZyQYYwXG":533,
"vhMiUYoP":null,
"ZuNWOmTB":"CXfWSv",
"QRNdvaTw":null,
"iNMNlmnF":0.4190763091619125
},
"iSWcHTIO":null,
"uKyQycTO":false,
"sBuIzWbu":0.6694282162218201,
"adnLMOYU":{
"wLNNApii":282,
"pRQHbDDo":null,
"bTKqUNTB":{
"xLJrAmZO":false,
"ozRzzKQl":"gptHP",
"mloyefuQ":{
"KJKZPuXV":226,
"JAWeYgpT":"bNwbOmd",
"qeecVexu":{
"apwyBxAk":194,
"OiuElOfF":117,
"jeEyedSl":false,
"dLuXVtAb":false,
"dUisByXt":true
},
"fKDfpSCg":"nLZBxXu",
"IebymleR":641
},
"FMIpHFKv":{
"aYPzFvbR":0.7541907525495641,
"wzPObCoG":false,
"CTEtTLVM":0.7087142420307628,
"DeJlLBvJ":"wkzjH",
"pBSwzrAG":0.6010343990209999
},
"pTyernLB":{
"zJlefedh":0.9942510052659024,
"HLwEcUeM":0.6765694010090948,
"QyArbAfr":{
"iZjyqkFr":{
"tJFlfHtV":978,
"NugJDCUy":0.559343013872208,
"GeumbRFN":"wmJK",
"AhVugKpt":false,
"fEspSVWS":null
},
"tRWmZara":null,
"HBaAFplj":null,
"qamkuwYn":{
"ULTpfton":0.4617637290099226,
"RoHyeWMb":false,
"RftXPJvH":null,
"NQpDbaKF":0.09060460894718836,
"coXPufnc":true
},
"CGrdlwyZ":"lVlreE"
},
"TovoWOgz":null,
"HsjrCaNP":null
}
},
"UhuFvmaJ":0.33299104895122267,
"HSjuxzDh":232
}
}, { TXzgcBbd: true,
SKxzRzNW: 0.9618236935424078,
CNLZbZcn: 286,
OsmfcuUG: 0.5933390334187918,
APBdqQZT: 697 }]
const arr2 = [ { TXzgcBbd: true,
SKxzRzNW: 0.9618236935424078,
CNLZbZcn: 286,
OsmfcuUG: 0.5933390334187918,
APBdqQZT: 697 }, {
"DnBoOgED":{
"ZyQYYwXG":533,
"vhMiUYoP":null,
"ZuNWOmTB":"CXfWSv",
"QRNdvaTw":null,
"iNMNlmnF":0.4190763091619125
},
"iSWcHTIO":null,
"uKyQycTO":false,
"sBuIzWbu":0.6694282162218201,
"adnLMOYU":{
"wLNNApii":282,
"pRQHbDDo":null,
"bTKqUNTB":{
"xLJrAmZO":false,
"ozRzzKQl":"gptHP",
"mloyefuQ":{
"KJKZPuXV":226,
"JAWeYgpT":"bNwbOmd",
"qeecVexu":{
"apwyBxAk":194,
"OiuElOfF":117,
"jeEyedSl":false,
"dLuXVtAb":false,
"dUisByXt":true
},
"fKDfpSCg":"nLZBxXu",
"IebymleR":641
},
"FMIpHFKv":{
"aYPzFvbR":0.7541907525495641,
"wzPObCoG":false,
"CTEtTLVM":0.7087142420307628,
"DeJlLBvJ":"wkzjH",
"pBSwzrAG":0.6010343990209999
},
"pTyernLB":{
"zJlefedh":0.9942510052659024,
"HLwEcUeM":0.6765694010090948,
"QyArbAfr":{
"iZjyqkFr":{
"tJFlfHtV":978,
"NugJDCUy":0.559343013872208,
"GeumbRFN":"wmJK",
"AhVugKpt":false,
"fEspSVWS":null
},
"tRWmZara":null,
"HBaAFplj":null,
"qamkuwYn":{
"ULTpfton":0.4617637290099226,
"RoHyeWMb":false,
"RftXPJvH":null,
"NQpDbaKF":0.09060460894718836,
"coXPufnc":true
},
"CGrdlwyZ":"lVlreE"
},
"TovoWOgz":null,
"HsjrCaNP":null
}
},
"UhuFvmaJ":0.33299104895122267,
"HSjuxzDh":232
}
}]
equivalent(arr1, arr2)
const arr1 = [{ KMFGNHeL: 0.2033444758693359,
HJMzVLhZ: 373,
WeKLrVwh: 'BlgvHn',
hutdufbF: 'dfalRd',
XqrwJjnR: null }, { xSUdtASV: 'ejVI',
pgUHOMNn: true,
dhQPzxuj: false,
MHUchilq: 719,
TWHkCOOT: 0.46691745627158165 }]
const arr2 = [{ fZhKYyQT: 379,
WtnguXmc: 64,
VaodnYbC: 0.7490618732830732,
hGhDbXmd:
{ pQnhfhKR: 0.029586390538915097,
oSpBStGM:
{ dKoUrTyg: 0.8023980228055398,
RMSlVEQw: null,
KiPTRmIf: 'GIfgX',
OOpGOzXD: null,
YSTcLKDa: 777 },
eDsjVaPK: null,
LrqwYwJs: 0.4117401997875565,
AbIoXBix: 'THmFh' },
anQZVYxA: 0.8284963046084715 }]
equivalent(arr1, arr2)
const arr1 = [54 ,34 ,16 ,100 ,64 ,19 ,88 ,93 ,43 ,58 ,44 ,83 ,98 ,72 ,88 ,4 ,93 ,2 ,23 ,95]
const arr2 = [54 ,34 ,16 ,100 ,64 ,19 ,88 ,93 ,43 ,58 ,44 ,83 ,98 ,72 ,88 ,4 ,93 ,2 ,23 ,95]
equivalent(arr1, arr2)
const arr1 = [54 ,34 ,16 ,100 ,64 ,19 ,88 ,93 ,43 ,58 ,44 ,83 ,98 ,72 ,88 ,4 ,93 ,2 ,23 ,95]
const arr2 = [54 ,34 ,64 ,100 ,16 ,19 ,88 ,43 ,93 ,58 ,44 ,83 ,88 ,72 ,98 ,4 ,93 ,2 ,23 ,95]
equivalent(arr1, arr2)
const arr1 = [54 ,34 ,16 ,100 ,64 ,19 ,88 ,93 ,43 ,58 ,44 ,83 ,98 ,72 ,88 ,4 ,93 ,2 ,23 ,95]
const arr2 = [79 ,12 ,38 ,68 ,6 ,40 ,67 ,93 ,98 ,48 ,64 ,45 ,33 ,6 ,73 ,43 ,7 ,57 ,10 ,77]
equivalent(arr1, arr2)
const arr1 = ['a', 'b', 'c', 'd']
const arr2 = ['a', 'b', 'c', 'd']
equivalent(arr1, arr2)
const arr1 = ['a', 'b', 'c', 'd']
const arr2 = ['b', 'a', 'd', 'c']
equivalent(arr1, arr2)
const arr1 = [{
"DnBoOgED":{
"ZyQYYwXG":533,
"vhMiUYoP":null,
"ZuNWOmTB":"CXfWSv",
"QRNdvaTw":null,
"iNMNlmnF":0.4190763091619125
},
"iSWcHTIO":null,
"uKyQycTO":false,
"sBuIzWbu":0.6694282162218201,
"adnLMOYU":{
"wLNNApii":282,
"pRQHbDDo":null,
"bTKqUNTB":{
"xLJrAmZO":false,
"ozRzzKQl":"gptHP",
"mloyefuQ":{
"KJKZPuXV":226,
"JAWeYgpT":"bNwbOmd",
"qeecVexu":{
"apwyBxAk":194,
"OiuElOfF":117,
"jeEyedSl":false,
"dLuXVtAb":false,
"dUisByXt":true
},
"fKDfpSCg":"nLZBxXu",
"IebymleR":641
},
"FMIpHFKv":{
"aYPzFvbR":0.7541907525495641,
"wzPObCoG":false,
"CTEtTLVM":0.7087142420307628,
"DeJlLBvJ":"wkzjH",
"pBSwzrAG":0.6010343990209999
},
"pTyernLB":{
"zJlefedh":0.9942510052659024,
"HLwEcUeM":0.6765694010090948,
"QyArbAfr":{
"iZjyqkFr":{
"tJFlfHtV":978,
"NugJDCUy":0.559343013872208,
"GeumbRFN":"wmJK",
"AhVugKpt":false,
"fEspSVWS":null
},
"tRWmZara":null,
"HBaAFplj":null,
"qamkuwYn":{
"ULTpfton":0.4617637290099226,
"RoHyeWMb":false,
"RftXPJvH":null,
"NQpDbaKF":0.09060460894718836,
"coXPufnc":true
},
"CGrdlwyZ":"lVlreE"
},
"TovoWOgz":null,
"HsjrCaNP":null
}
},
"UhuFvmaJ":0.33299104895122267,
"HSjuxzDh":232
}
}, { TXzgcBbd: true,
SKxzRzNW: 0.9618236935424078,
CNLZbZcn: 286,
OsmfcuUG: 0.5933390334187918,
APBdqQZT: 697 }]
const arr2 = [ { TXzgcBbd: true,
SKxzRzNW: 0.9618236935424078,
CNLZbZcn: 286,
OsmfcuUG: 0.5933390334187918,
APBdqQZT: 697 }, {
"DnBoOgED":{
"ZyQYYwXG":533,
"vhMiUYoP":null,
"ZuNWOmTB":"CXfWSv",
"QRNdvaTw":null,
"iNMNlmnF":0.4190763091619125
},
"iSWcHTIO":null,
"uKyQycTO":false,
"sBuIzWbu":0.6694282162218201,
"adnLMOYU":{
"wLNNApii":282,
"pRQHbDDo":null,
"bTKqUNTB":{
"xLJrAmZO":false,
"ozRzzKQl":"gptHP",
"mloyefuQ":{
"KJKZPuXV":226,
"JAWeYgpT":"bNwbOmd",
"qeecVexu":{
"apwyBxAk":194,
"OiuElOfF":117,
"jeEyedSl":false,
"dLuXVtAb":false,
"dUisByXt":true
},
"fKDfpSCg":"nLZBxXu",
"IebymleR":641
},
"FMIpHFKv":{
"aYPzFvbR":0.7541907525495641,
"wzPObCoG":false,
"CTEtTLVM":0.7087142420307628,
"DeJlLBvJ":"wkzjH",
"pBSwzrAG":0.6010343990209999
},
"pTyernLB":{
"zJlefedh":0.9942510052659024,
"HLwEcUeM":0.6765694010090948,
"QyArbAfr":{
"iZjyqkFr":{
"tJFlfHtV":978,
"NugJDCUy":0.559343013872208,
"GeumbRFN":"wmJK",
"AhVugKpt":false,
"fEspSVWS":null
},
"tRWmZara":null,
"HBaAFplj":null,
"qamkuwYn":{
"ULTpfton":0.4617637290099226,
"RoHyeWMb":false,
"RftXPJvH":null,
"NQpDbaKF":0.09060460894718836,
"coXPufnc":true
},
"CGrdlwyZ":"lVlreE"
},
"TovoWOgz":null,
"HsjrCaNP":null
}
},
"UhuFvmaJ":0.33299104895122267,
"HSjuxzDh":232
}
}]
_equiv(arr1, arr2)
const arr1 = [{ TXzgcBbd: true,
SKxzRzNW: 0.9618236935424078,
CNLZbZcn: 286,
OsmfcuUG: 0.5933390334187918,
APBdqQZT: 697 }, { TXzgcBbd: true,
SKxzRzNW: 0.9618236935424078,
CNLZbZcn: 286,
OsmfcuUG: 0.5933390334187918,
APBdqQZT: 697 }]
const arr2 = [{ TXzgcBbd: true,
SKxzRzNW: 0.9618236935424078,
CNLZbZcn: 286,
OsmfcuUG: 0.5933390334187918,
APBdqQZT: 697 }, { TXzgcBbd: true,
SKxzRzNW: 0.9618236935424078,
CNLZbZcn: 286,
OsmfcuUG: 0.5933390334187918,
APBdqQZT: 697 }]
_equiv(arr1, arr2)