mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-09-20 07:43:04 +08:00
added _toString method
This commit is contained in:
parent
1bb83c6866
commit
8a88cbc455
@ -86,6 +86,12 @@ class MerkleTree {
|
||||
const hash = crypto.createHash(method)
|
||||
return hash.update(node, 'utf8').digest('hex')
|
||||
}
|
||||
_toString(node) {
|
||||
if (node.constructor === String) return node
|
||||
if (node.constructor === Number) return node.toString()
|
||||
if (node.constructor === Object) return JSON.stringify(node)
|
||||
throw new Error('Input object only takes string, number, object')
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user