lodash xor vanila toggle
lodash xor for toggling value vs es6 includes if else
Date tested:
one year ago
User agent:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:101.0) Gecko/20100101 Firefox/101.0
Test name
Executions per second
lodash xor implemantation
28446.6 Ops/sec
alternative with Sets
195014.3 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
var a = Array(256).fill(0).map((_, index) => index) a.push('foo') var b = 'foo'
Tests:
lodash xor implemantation
const res = _.xor(a, [b])
alternative with Sets
function toggleValueInArray(value, list) { if (list.includes(value)) { list.filter(listValue => listValue !== value) } else { return [...list, value] } } const res = toggleValueInArray(b, a)
Open this result on MeasureThat.net