FAC10 / week5-jajascript

Never miss a train leaving from Bethnal Green again
https://week5-jajascript-bethnal-green.herokuapp.com/
5 stars 1 forks source link

Combining let & var statements #56

Closed njsfield closed 7 years ago

njsfield commented 7 years ago

Any reason why you're combining let and var declarations in tflLogic.js ?

  let westbound = [];
  let eastbound = [];
  var arr = data.map((value)=>[value.platformName, value.towards, value.timeToStation]);
  var sorted = arr.sort((a, b) => {
    return a[2] - b[2];
  })

Let is block scoped and var is not, see here for further info (in general, var is virtually never needed if you're working in an environment which allows ES6 syntax).

Aside from that, all of these variables (westbound, eastbound, arr, sorted) are not redefined anywhere in your code, so you can store them as constants to ensure that don't get overridden by mistake;

  const westbound = [];
  const eastbound = [];
  const arr = data.map((value)=>[value.platformName, value.towards, value.timeToStation]);
  const sorted = arr.sort((a, b) => {
    return a[2] - b[2];
  })

See here

alexis-l8 commented 7 years ago

Thanks for your detailed response. The plan is to have the site refresh via setInterval so that the train arrival times refresh every few seconds. Therefore I will change the VARs to LETs.