Remix.run Logo
WorldMaker a day ago

JS is a fun language where argument defaults can accidentally shoot you in the foot because of no runtime type checking of argument application. With your example, you might want to map a bunch of lengths through it, which in simplest form might look:

    someLengthArray.map(randString)
The classic surprise is that map provides 2 arguments with the second argument being the index of the array. Depending on how `randString(length, alphabet)` uses its alphabet it might just use the string form of the index so you accidentally get random strings of n length '0' then '1' then '2', etc.

(The most common case of this problem in JS is probably `parseInt(string, radix = 10)`. Accidental arbitrary radix from an index parameter is a fun way to get unexpected numbers back from your array of strings.)