My journey into algorithms

·

2 min read

I understand a lot of companies require algorithms for their interview and for the longest time, I have avoided it. But today, for the third time, I am going back to algorithms. Here is a simple problem that I solved:

I am currently using scotch.io. I know that it's shutting down in a few months so hopefully, I'll save everything.

Anyways, the first problem is a reverseString problem. So basically, take a word and reverse it. I admit that I have no idea and according to Leon Noel (Seriously, check him out. 100% legit.) It's okay to look up the answer after twenty minutes or so. Since I flat out suck at this, I immediately, looked up the possible solutions. However, instead of copy and paste, understand each line so you can know how the code works.

function reverseString(text) { <-- your function. In the paranentheses , text is put in.

return text.split("").reverse().join("") <-- .split puts the word into an array and the quotes will make the word like this("H","E","L","L","O") and reversing it will make the word like this("O","L","L","E",H") and .join will make the individual letters into a word. 

}

console.log(reverseString("Hello World"))<-- Hello World is the word I want to use to see if the process is successful.

image.png Looks like it was! Yay. Here is the end result: image.png Yay! Hopefully, the next chapter is not too hard.