Create an array of characters from specified range

后端 未结 12 2239
名媛妹妹
名媛妹妹 2020-12-17 08:19

I read some code where someone did this in Ruby:

puts (\'A\'..\'Z\').to_a.join(\',\')

output:

A,B,C,D,E,F,G,H,I,J,K,L,M,N,O         


        
12条回答
  •  清歌不尽
    2020-12-17 09:00

    function range(r, x) {
        var c1 = r.charCodeAt(0)+1, c2 = r.charCodeAt(3), s = r[0];
        if(c1 && c2)while (c1 <= c2) s += (x || "") + String.fromCharCode(c1++);
        return s;
    }
    
    range("A--S", ",");
    

提交回复
热议问题