Mastering JavaScript

Mastering JavaScript

News From hn.algolia About JavaScript

JavaScript powers the web - it's the most important programming language you need to know as a web developer.

Exempel 1

For example, We have an array of different objects that can weigh the same or different and are spaced apart from us. The customer wants the lightest and closest object.

object.sort((a,b)=>a.weigh - b.weigh)

    const lightest=(object[0].weigh);
    let sortDistance=(object[0].distance);        

    for (let i = 0; i< object.length; i++) {      
      if (lightest === object[i].weigh && sortDistance > object[i].distance){
         sortDistance = object[i].distance;
         sortObject.unshift(object[i]);
      }else{
         sortObject.push(object[i]);
      }
    }

... more comming soon