Last active
April 20, 2019 16:39
-
-
Save dfkaye/ea45ec072269d23dec993f46b3ebccbe to your computer and use it in GitHub Desktop.
random-hex-string - create a random hex value string
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
// Dec 27, 2018 | |
// create a random hex value string | |
var hex = function() { | |
return Math.floor(Date.now() * Math.random()).toString(16); | |
} | |
// test it out | |
var values = Array(1000000).fill(0).map(function() { | |
return hex(); | |
}); | |
// track any duplicate values | |
var dupes = values.reduce(function(dupes, value) { | |
value in dupes.visited || (dupes.visited[value] = 0); | |
dupes.visited[value] += 1; | |
if (dupes.visited[value] > 1) { | |
dupes.values[value] = dupes.visited[value] | |
} | |
return dupes; | |
}, { values: {}, visited: {} }); | |
console.log(Object.keys(dupes.values).length); | |
console.log(dupes.values); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment