Coding Interview Trick Using ASCII - JavaScript

preview_player
Показать описание
Here is an interesting trick that uses ASCII to print the characters of the alphabet to an array, useful for coding interviews at companies like Microsoft, Amazon, Apple and Google

#softwareengineering #javascript #codinginterview #shorts
Рекомендации по теме
Комментарии
Автор

if you want to validate a string, you don't even need to make an array of valid symbols, you can compare character codes instead.
so, if char is code of a character of the string, then:
(char >= 65 && char <= 90) returns true if char represents a capital latin letter,
char >= 97 && char <= 122 // returns true if char represents a small latin letter,
char >= 48 && char <= 57 // returns true if char is a digit
and you can || those checks if you want any of them to be triggered.
you can also check for individual characters like space (32), full stop (46) or underscore (95).

WebMafia
Автор

you can use charCodeAt() to retrieve the index (unicode) of a :
const indexOfA = ('a').charCodeAt(0);
const indexOfZ = ('z').charCodeAt(0);

kappitain
Автор

Java script is in the development tools in the top right that opens a window in your browser on the right

Mr..i
Автор

A cool useless trick for what is basically a constant

SXsoft