Does anyone know of a Javascript library (e.g. underscore, jQuery, MooTools, etc.) that offers a method of incrementing a letter?
I would like to be able to do somet
Make a function with {a: 'b', b: 'c', etc} in a closure:-
let nextChar = (s => (
"abcdefghijklmopqrstuvwxyza".split('')
.reduce((a,b)=> (s[a]=b, b)), // make the lookup
c=> s[c] // the function returned
))({}); // parameter s, starts empty
usage:-
nextChar('a')
Adding uppercase and digits:-
let nextCh = (
(alphabeta, s) => (
[alphabeta, alphabeta.toUpperCase(), "01234567890"]
.forEach(chars => chars.split('')
.reduce((a,b) => (s[a]=b, b))),
c=> s[c]
)
)("abcdefghijklmopqrstuvwxyza", {});
p.s. In some versions of Javascript, you can use [...chars] instead of chars.split('')