Do you have a tech interview coming up? Read this…

Ludmila Korchnoy
1 min readSep 9, 2021

In my job search, at tech interviews I get asked different algorithms to solve. I will share with you one of them that is rather simple, useful and good to know. When asked to count words in a sentence or count letters in a word, my favorite function is to accomplish it the following way:

function countingExampe(s) {

return s.trim().split(/\s+/).length;

}

You can use s.split(“ “).length method as well.

String.trim() method removes whitespace from both sides of the string without changing the string. Split() method returns an array of substrings, for example Do you have a tech interview today? will return Do,you,have,a,tech,interview,today? Separator is used to separate each character. The regex expression I used will do the same thing as split(“ “) method. Here is the link to Regular Expression syntax cheatsheet

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet

Do you have a tech interview coming up — you got this! Happy coding!

--

--

Ludmila Korchnoy

Hello World! I’m a Full stack web developer experienced in Ruby and JavaScript frameworks. I graduated Flatiron School in October of 2020.