Javascript Coding Challenges for Beginners Q1

Transcript

English (Auto-generated)

Hello everyone. Welcome to my javascript coding challenge course for beginners. In this course, I have included a list of important javascript concepts and apply them into coding challenges. Let's go right ahead to the first question. In this challenge we have a very simple whiteboard question that you will often see in your coding interviews which is fixing a simple javascript function. Whether it is there syntax or improving their functionality, they may or may not tell you how many lines to fix. So it's very important to ask your interviewer questions at this time. But for this coding challenge you will have to edit no more than two lines of code. Let's take a look at the question. The function solutions takes in the list of strings and returns each line pretended by the correct number. The number will start at one and the format is an end strings. The function will also return an empty array if the array is empty. So we look on the left side here, we can see that we have to fix the javascript function below and we also have the solutions provided, which encoding challenges you probably won't get but for the sake of this tutorial we will provide it here. So it's easier for you to compare. Now, pause the video and take a few minutes to come up with their own solution. Press play when you're ready and we will solve the challenge together now that you're ready. We will go through the solution line by line. The first line line. Forest says that if the array length zero we return an empty bracket Which is true because an empty array has a length of zero. Now moving to line six we have four loop. And it looks correct to me because when we want to manipulate theory to create a new list of strengths But online seven, it is saying that the array itself will be equal to a new string which seems to be incorrect to me because we do want to return an array for the output and not a string. So one way to manipulate the elements inside the array is by passing a new value to the current element and we can do that by fixing theory by signing the current element back to it. Now that line seven is saying for the current elements we want to change it. So it's index plus one plus semi colon plus array I So for example if the index is +00 plus one is one. If we add a semi colon is one semi colon. If we add the current element I which is array zero, it would be a So our first answer would be one semi colon A. If we move on to the next iteration we should get to be and three seats if you want to check your solution, we can simply do that by consul long easier. Right, So let's do that. Okay if you have never used your terminal and your V. S code before, you can simply do that by going to the top, like on terminal and new terminal. So let's try that. Great. Our answer is exactly the same as our solution. Congratulations on completing the first coding challenge, and when you're ready, we can move onto the next challenge.
270 Views 1 Likes 1 Comments

The goal of this course is to improve your coding skills and learn how to tackle javascript coding challenges.

Comment
Leave a comment (supports markdown format)
@jesusvilla 2 years ago

Fun, byte-sized challenge. My solution before actually watching the video:

macos@home $ node
> const solution = (strings) => strings.map((str, index) => `${index+1}: ${str}`)
undefined
> solution(['first string', 'second second'])
[ '1: first string', '2: second second' ]

I love problems like this, which can be solved in so many different ways.