-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update readme and tests, removed toInt() method
- Loading branch information
pavlik
committed
May 12, 2021
1 parent
03a7a49
commit f8e197e
Showing
4 changed files
with
38 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,21 @@ | ||
Object.defineProperty(Object.prototype, 'toInt', { | ||
value: function (){ | ||
let key = this.toString(); | ||
if(parseInt(key).toString() === key) return Math.abs(parseInt(key)); | ||
let h = 0, i = key.length; | ||
while (i > 0) { | ||
h = (h << 5) - h + key.charCodeAt(--i) | 0; | ||
} | ||
return Math.abs(h); | ||
}, | ||
enumerable: false | ||
}); | ||
|
||
Object.defineProperty(Object.prototype, 'to', { | ||
value: function (map){ | ||
|
||
function toInt(key){ | ||
if(parseInt(key).toString() === key) return Math.abs(parseInt(key)); | ||
let h = 0, i = key.length; | ||
while (i > 0) { | ||
h = (h << 5) - h + key.charCodeAt(--i) | 0; | ||
} | ||
return Math.abs(h) | ||
} | ||
|
||
if(typeof map === "undefined") return this.toString(); | ||
let int = this.toString().toInt(); | ||
let int = toInt(this.toString()); | ||
let nodes = Array.from(map).sort((a, b) => a - b); | ||
|
||
return nodes[int % nodes.length]; | ||
}, | ||
enumerable: false | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters