5 ms·
If you’re doing this in a serious setting, use a stable JSON stringification (like json-stable-stringify) that sorts object keys, and then take the SHA of the r
by mayank 8y ago
If you’re doing this in a serious setting, use a stable JSON stringification (like json-stable-stringify) that sorts object keys, and then take the SHA of the resulting string.
Better collision properties, easier to implement, and a cryptographic hash to boot, just as long as you don’t have circular references and only care about the serializable “contents” of an object.
- davidjnelson 8y agoIt would be nice to have a library that had es6 data structures such as set, but supported object hash codes using a technique like this. That’s a weird thing missing in the js standard lib.