bigmachine-io / mission-interview

Code and Issues for Mission: Interview Production
4 stars 1 forks source link

Islands In The Sea - setSail Improvement #9

Closed sagivf closed 5 years ago

sagivf commented 5 years ago

I believe that when you setSail there is no need to go over land that has already been sailed and mapped. Am I correct?


  let lat = 0
  let lon = 0
  const setStail = () => {
    for (; lat < ocean.length; lat++) {
      for (; lon < ocean[lat].length; lon++) {
        if (ocean[lat][lon] === 1) {
          return {lat, lon}
        }
      }
      lon = 0;
    }
    return false
  }
``
robconery commented 5 years ago

I think it might save on some things but I don't think it effects the overall time complexity. Either way - nice tweak :).

sagivf commented 5 years ago

I believe your correct, just wanted to see I wasn't missing anything, thanks :)