DEV Community

[Comment from a deleted post]
Collapse
 
snakebdd profile image
Bob

So why not directly use table[key] = value?

 
marklai1998 profile image
Mark Lai

My first impression is the same as yours
But after I realised the implementation, everything will be correct

if you use table[key], there is no way to detect if an element already exists in the object, especially you are using UUID for the key part

but the solution is to use the hash of that object as the UUID and the key, so you can have everything unique(the same element will give same hash), but still can add "infinite amount" of element without implementing your key generator

the code example is just an example