Michael Pautov

Software Engineer

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.

let input = [
  { 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.

let input = [
  { 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 extractValues = (arr, property) => {
  let output = [];

  for (let i = 0; i < arr.length; i++) {
    output.push(arr[i][property]);
  }

  return output;
};

let result = extractValues(input, "name");
console.log(result);

In the above code, a function is created so that the code looks more organized. Remember, …….

Source: https://hackernoon.com/top-three-coding-challenges-for-mid-level-javascript-developers

Leave a comment

Your email address will not be published. Required fields are marked *