Dev position interviews – live coding

During a recent phone interview I was asked to live-code in Javascript using coderpad.io.  I never had to live code for someone before, and it didn’t go great… so I have been working on algorithm coding practice.  I’m using coderbyte.com, and I have been going through a YouTube video from Traversy Media (https://www.youtube.com/watch?v=M2bJBuaOeOQ&list=PLillGF-Rfqbb4ZOnsNCIB-DnLuUrQjS_G).

One common problem seems to be reversing a string.  There are a variety of ways to do it, but I think this is the most straightforward:

function reverse(str) {

const reverse = str.split(“”).reverse().join(“”);

console.log(reverse);

}

reverse(“Hello”); // expected return olleH

In one line, I split the string into an array, reversed the letters (elements of the array), then combined the array elements back into a string.  There are many ways to do this.  I could also have done a basic “for” loop, or used “forEach()”, “map()” or “reduce()” methods as well.

Once you understand this basic concept, you can apply it to the Palindrome problem (finding words that are spelled the same backward or forwards, like “racecar”) or the reverse integer problem.

Leave a Reply

Your email address will not be published.