Level up your JavaScript Coding Skills If you have a considerable amount of experience with JavaScript, you are expected to solve complex coding challenges. For beginners, JavaScript coding challenges are not that big a deal. But an experienced JavaScript developer should know how to understand and solve coding challenges efficiently. A JavaScript developer can be categorized into one of the following categories according to experience. Beginner Mid-level Experienced In this article, we will discuss three coding JavaScript challenges for mid-level developers. Extract the values of a given Property From an Array of Objects An experienced JavaScript should have a proper working knowledge of arrays and objects because these data structures are heavily used in modern JavaScript development. By giving this coding challenge, the interviewers want to see the developer’s approach for working with arrays and objects. The following can be the input. input = [ { : , : , : }, { : , : , : }, { : , : , : }, { : , : , : }, { : , : , : }, ]; let name "John" age 21 city "New York" name "Mike" age 28 city "Moscow" name "Danny" age 30 city "London" name "Lisa" age 26 city "Paris" name "Sophie" age 19 city "Berlin" For this challenge, the value of the “name” property from every object should be extracted and stored in an array. The output should be like the following: [ , , , , ]; "John" "Mike" "Danny" "Lisa" "Sophie" To solve this challenge, take an empty array and then iterate through the array of objects. With every iteration, push the value of the “name” property for every object using the in-built push() function. input = [ { : , : , : }, { : , : , : }, { : , : , : }, { : , : , : }, { : , : , : }, ]; extractValues = { output = []; ( i = ; i < arr.length; i++) { output.push(arr[i][property]); } output; }; result = extractValues(input, ); .log(result); let name "John" age 21 city "New York" name "Mike" age 28 city "Moscow" name "Danny" age 30 city "London" name "Lisa" age 26 city "Paris" name "Sophie" age 19 city "Berlin" const ( ) => arr, property let for let 0 return let "name" console In the above code, a function is created so that the code looks more organized. Remember, an experienced developer is expected to write clean and organized code. The above code will solve the challenge but there is one problem. An experienced JavaScript Engineer should use ES6 syntax instead of the older ES5 syntax. So let’s replace the for loop with the ES6 map() function. extractValues = { output = arr.map( element[property]); output; }; const ( ) => arr, property let ( ) => element return So this coding challenge checks whether you know how to work with arrays and objects in JavaScript with the help of ES6 syntax. Rotate the String k Times in the Left Direction Along with Numbers, strings are the most commonly used data types in Javascript. An experienced JavaScript developer should know how to work with strings and should have the proper knowledge of in-built string functions. A string along with a number will be the input. string = n = let "javascript" let 2 According to the above input, the given string should be rotated two times in the left direction. Following should be the output. "vascriptja" This coding challenge is to check your string knowledge and how you write the logic. The simplest way to solve this challenge is by making the right use of the in-built substring() function. { part1 = string.substring(n, string.length); part2 = string.substring( , n); output = part1 + part2; output; } string = ; n = ; .log(rotateLeft(string, n)); ( ) function rotateLeft string, n let let 0 let return let "javascript" let 2 console When n = 2, the first two characters - “ja” are removed and added to the end, this rotating the string to the left two times. So first, the substring except the first two characters is extracted (part1) and then those two remaining characters (part2) are extracted as substring using the same function. Finally, both the substrings are concatenated. Calculate the Number of Days Between Two Dates The motive of this coding challenge is to check your level of experience with JavaScript. A beginner, usually, does not have any working experience with dates but an experienced developer must have worked with dates because working with dates is a common part of JavaScript development. The input will consist of two dates in DD/MM/YYYY format. date1 = ; date2 = let "08/10/2021" let "09/11/2021" To solve this challenge, you must know which in-built date function to use. findDays = { d1 = (date1); d2 = (date2); difference = d2.getTime() - d1.getTime(); output = difference / ( * * ); .floor(output); }; date1 = ; date2 = ; .log(findDays(date1, date2)); const ( ) => date1, date2 let new Date let new Date let let 1000 3600 24 return Math let "11/01/2021" let "11/03/2021" console As mentioned, knowledge of date functions is required to solve this challenge. Here, first, the date is converted into the right format, and then, the getTime() method is used to find the time difference between the dates. Another motive of this challenge is to check your calculation solving technique by asking you to find the days using the difference in the time. Wrapping it Up The coding challenges for mid-level experienced JavaScript developers usually focus on the knowledge of JavaScript that could be attained only through experience. For example, the date coding challenge. Another important area is the knowledge of ES6. Moreover, the clarity of concepts such as arrays, objects, and strings is very important for mid-level JavaScript developers. Last but not the least, the style of coding is also considered for an experienced JavaScript developer.
Share Your Thoughts