pelaha.blogg.se

Javascript coding
Javascript coding




The ES6 solution takes another approach with using the Math object property max as a shortcut for the conditional logic in the ES5 version. In the ES5 solution, we utilized a conditional statement to see if the current ( arr) string’s length is longer than (but not equal to) the current longest string( longest). In JavaScript, we can do that with the length property.

javascript coding

We are using the array method forEach to iterate over the array in the ES6 solution.Īs we iterate through the data structure, we want to take a look at the length of each string. In the ES5 solution, we are utilizing a traditional for loop structure to look at each index in the array. In both solutions, we initially need to declare a longest variable and initialize it to an empty string. There are two different ways listed here as a possible solution to this problem: one uses the ES5 Syntax and uses the ES6 Syntax. As long as you can explain your thought-process in good detail, your answer is probably fine! Keep in mind that there are several ways to solve these problems.

  • Refactor - is There a Way to Make it Better?Īs we challenge ourselves in the next ten problems, keep these steps in mind.
  • javascript coding

    One of the ways to make them easier is to follow principles outlined in a short book by George Polya called How To Solve It. JavaScript challenges can be difficult enough without us trying to make them harder for ourselves. If you’re an absolute beginner, it will be helpful to check out our beginner’s guide before diving in. These exercises are useful for any JavaScript developer. That’s why today we will go over 10 coding challenges to level up your JavaScript skills.

    javascript coding

    The best way to learn JavaScript is to practice, practice, practice.






    Javascript coding