Skip to content

Instantly share code, notes, and snippets.

@klashxx
Last active October 17, 2018 14:33
Show Gist options
  • Save klashxx/118deea6693d0f92ac6c665706e550b6 to your computer and use it in GitHub Desktop.
Save klashxx/118deea6693d0f92ac6c665706e550b6 to your computer and use it in GitHub Desktop.

JS Tricks

Consecutive letter array

Array.from(new Array(6),(_,index)=> String.fromCharCode('a'.charCodeAt(0) + index))

Results

Array [ "a", "b", "c", "d", "e", "f" ]

Two dimensional array simulating a plane seating map:

Array.from(
  Array(30), () => Array.from(
    new Array(6),(_,index)=> String.fromCharCode('a'.charCodeAt(0) + index)
  )
)

Results

[…]
0: Array [ "a", "b", "c", … ]
1: Array [ "a", "b", "c", … ]
2: Array [ "a", "b", "c", … ]
3: Array [ "a", "b", "c", … ]
4: Array [ "a", "b", "c", … ]
5: Array [ "a", "b", "c", … ]
6: Array [ "a", "b", "c", … ]
7: Array [ "a", "b", "c", … ]
8: Array [ "a", "b", "c", … ]
9: Array [ "a", "b", "c", … ]
10: Array [ "a", "b", "c", … ]
11: Array [ "a", "b", "c", … ]
12: Array [ "a", "b", "c", … ]
13: Array [ "a", "b", "c", … ]
14: Array [ "a", "b", "c", … ]
15: Array [ "a", "b", "c", … ]
16: Array [ "a", "b", "c", … ]
17: Array [ "a", "b", "c", … ]
18: Array [ "a", "b", "c", … ]
19: Array [ "a", "b", "c", … ]
20: Array [ "a", "b", "c", … ]
21: Array [ "a", "b", "c", … ]
22: Array [ "a", "b", "c", … ]
23: Array [ "a", "b", "c", … ]
24: Array [ "a", "b", "c", … ]
25: Array [ "a", "b", "c", … ]
26: Array [ "a", "b", "c", … ]
27: Array [ "a", "b", "c", … ]
28: Array [ "a", "b", "c", … ]
29: Array [ "a", "b", "c", … ]
length: 30
__proto__: Array []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment