Last active
December 23, 2017 16:46
-
-
Save pombadev/310d61358173601b86490c23f9c10514 to your computer and use it in GitHub Desktop.
basic non-uuid uuid generator without going crazy!
This file contains hidden or 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
// with map | |
[...Array(5)].map((elm, idx) => { | |
switch(idx) { | |
case 0: | |
return Math.random().toString(36).slice(2, 8) | |
case 4: | |
return Math.random().toString(36).slice(2, 14) | |
default: | |
return Math.random().toString(36).slice(2, 6) | |
} | |
}).join('-') | |
// with reduce | |
[...Array(5)].reduce((total, elm, idx) => { | |
if (idx === 0) { | |
total = Math.random().toString(36).slice(2, 8) + '-' | |
} else if (idx === 4) { | |
total += Math.random().toString(36).slice(2, 14) | |
} else { | |
total += Math.random().toString(36).slice(2, 6) + '-' | |
} | |
return total | |
}, '') | |
// returns "ahxiz7-xzec-xn2c-8di9-btlq6e3k9wg" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment