Advertisement
LastShadowPL

String range

May 27th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String.prototype[Symbol.iterator] = function* () {
  2.     if (this.length > 1) {
  3.         for (const i in this) yield this[i]
  4.     } else {
  5.         for (let code = 65; code <= this.charCodeAt(0); code++) {
  6.             const c = String.fromCharCode(code)
  7.             yield c
  8.             // Word characters only
  9.             // if ((/\w/).test(c)) yield c
  10.         }
  11.     }
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement