JSFiddle - React, Tailwind, and code Playground
by mich
JavaScript
function List() {
this.arr = [];
}
List.prototype.add = function (obj) {
if (this.arr.indexOf(obj) !== -1) {
return; // already in list
}
this.arr.push(obj);
}
List.prototype.remove = function (obj) {
var i = this.arr.indexOf(obj);
if (i === -1) {
return;
// Not found in list, ignore
}
// Remove the obj where it was found on the list
this.arr.splice(i, 1);
}