Created
April 14, 2024 00:17
-
-
Save ValchanOficial/99913fd8f5ae1f7e4c9c4156e282c887 to your computer and use it in GitHub Desktop.
[Javascript] Create alphanumeric code
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
export const alphanumeric = (len) => { | |
const str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | |
return [...Array(len)].reduce( | |
(a) => a + str[~~(Math.random() * str.length)], | |
"" | |
); | |
}; | |
console.log(alphanumeric(6)); // HNF2RU |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment