javascript increment alphabet
class StringIdGenerator {
constructor(chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
this._chars = chars;
this._nextId = [0];
}
next() {
const r = [];
for (const char of this._nextId) {
r.unshift(this._chars[char]);
}
this._increment();
return r.join('');
}
_increment() {
for (let i = 0; i < this._nextId.length; i++) {
const val = ++this._nextId[i];
if (val >= this._chars.length) {
this._nextId[i] = 0;
} else {
return;
}
}
this._nextId.push(0);
}
*[Symbol.iterator]() {
while (true) {
yield this.next();
}
}
}const ids = new StringIdGenerator();
ids.next(); // 'a'
ids.next(); // 'b'
ids.next(); // 'c'
// ...
ids.next(); // 'z'
ids.next(); // 'A'
ids.next(); // 'B'
// ...
ids.next(); // 'Z'
ids.next(); // 'aa'
ids.next(); // 'ab'
ids.next(); // 'ac'
Also in JavaScript:
- how to check if a key exists in an object javascript
- jquery .click function call
- $(...).DataTable is not a function
- statusbar reactnati
- AttachConsole failed with error 6: The handle is invalid.
- electron file association
- how to parse json in java
- Write a regular expression to validate phone number in XXX-XXX-XXXX format?
- button click function in js
- index and id together angularjs
- delete local storage javascript
- how to clear cache of gradle
- How to replace an array vue.js
- jquery disable enter key submit
- webview javascript enabled
- Cast to ObjectId failed for value
- node js write read string to file
- angular firebase
- js dom ready function
- react and bootstrap
- show hand icon on hover javascript
- add class javascript
- js propagation stop
- read xlsx file in angular 5