String that contains all ascii characters

前端 未结 7 1295
灰色年华
灰色年华 2021-02-03 23:01

I want to create a string in JavaScript that contains all ascii characters. How can I do this?

7条回答
  •  一向
    一向 (楼主)
    2021-02-03 23:43

    Here is a version in coffeescript

    require 'fluentnode'
    
    all_Ascii = ->
      (String.fromCharCode(c) for c in  [0..255])
    
    describe 'all Ascii', ->
    
      it 'all_Ascii', ->
        all_Ascii.assert_Is_Function()
        all_Ascii().assert_Size_Is 256
        all_Ascii()[0x41].assert_Is 'A'
        all_Ascii()[66  ].assert_Is 'B'
        all_Ascii()[50  ].assert_Is '2'
        all_Ascii()[150 ].assert_Is String.fromCharCode(150)
    

提交回复
热议问题