code: function(points, firstPoint, lastPoint, tolerance){
                  var maxDistance = 0;
                  var indexFarthest = 0;
      
                  for (var index = firstPoint, distance; index < lastPoint; index++) {
                      distance = perpendicularDistance(points[firstPoint], points[lastPoint], points[index]);
                      if (distance > maxDistance) {
                          maxDistance = distance;
                          indexFarthest = index;
                      }
                  }
      
                  if (maxDistance > tolerance && indexFarthest != firstPoint) {
                      //Add the largest point that exceeds the tolerance
                      pointIndexsToKeep.push(indexFarthest);
                      douglasPeuckerReduction(points, firstPoint, indexFarthest, tolerance);
                      douglasPeuckerReduction(points, indexFarthest, lastPoint, tolerance);
                  }
              }
docs: Private function doing the Douglas-Peucker reduction