JSFiddle - React, Tailwind, and code Playground
JavaScript
class Set {
constructor( array = [] ) {
this.data = array;
}
equals(element1, element2) {
return JSON.stringify(element1) === JSON.stringify(element2);
}
indexOf(element) {
for(var i = 0; i < this.data.length; i++) {
if( this.equals(this.data[i], element) ) {
return i;
}
}
return -1;
}
has(element) {
return this.indexOf(element) != -1;
}
add(element) {
if( !this.has(element) ) {
this.data.push( element );
}
}
remove(element) {
this.data.splice( this.indexOf(element), 1 );
}
elements() {
return this.data;
}
}
var s = new Set();
s.add([2,3]);
s.add([3,4]);
console.log( s.elements() );
console.log( s.has([2,3]) );