title: JS function more compact
body: <p>I have a function who use coordinates,</p>
  <p>I looking for a way to have a DRY code</p>
  <p>this is a part of my code :
  <a href="https://codepen.io/sebastiancz/pen/LYGLXjW?editors=1010" rel="nofollow noreferrer">https://codepen.io/sebastiancz/pen/LYGLXjW?editors=1010</a></p>
  <p>a part a my code</p>
  <pre><code>
   const coordinate = {&quot;x&quot;: x, &quot;y&quot;: y};
                  this.tilesCoordinates.push(coordinate);
                  const max = this.tilesCoordinates.length - 1;
                  const curr = this.tilesCoordinates[max];
                  const prev = this.tilesCoordinates[max - 1];
                  ....
  </code></pre>
  <p>thanks for your help</p>