Increment a string with letters?

前端 未结 12 1285
礼貌的吻别
礼貌的吻别 2021-02-08 12:35

I need to increment a string from.. let\'s say aaa to zzz and write every incrementation in the console (is incrementation even a word?). It would go s

12条回答
  •  感情败类
    2021-02-08 12:56

    Interesting approach with Number#toString:

    var n = 13330
    var ns = []
    
    for(var i = 0; i < 26; i++) {
      for(var j = 0; j < 26; j++) {
        for(var k = 0; k < 26; k++) {
          ns.push(n.toString(36))
          n++
        }
        n += 10 // jump from '(x)0' to '(x+1)a', etc.
      }
      n += 360 // jump from '(x)0a' to '(x)aa', etc.
    }
    
    console.log(ns) // the strings you wanted
    

提交回复
热议问题