secretgspot
10/7/2019 - 3:16 AM

FUNCTIONS

/*
.___.  ..  . __ .___.._..__..  . __.
[__ |  ||\ |/  `  |   | |  ||\ |(__ 
|   |__|| \|\__.  |  _|_|__|| \|.__)
*/

/* ▀▀▀ // Curried function */
function addition(x) {
   return function(y) {
     return x + y;
   }
}
var addThreeTo = addition(3);
addThreeTo(6);


/* ▀▀▀ // declared IIFE */
var smplMsg = 
(simpleMessage = (msg) => {
  console.log(msg || 'hi');
});

/* ▀▀▀ // degToRad */
function degToRad(degree) {
  return degree * Math.PI/180;
}

/* ▀▀▀ // WSGtoXYZ */
function WSGtoXYZ(location, R) {
  let xyz = {x:0, y:0, z:0};
  xyz["y"] = Math.sin(degToRad(location.lat))*R;
  let r = Math.cos(degToRad(loaction.lat))*R;
  xyz["x"] = Math.sin(degToRad(location.lng))*r;
  xyz["z"] = Math.cos(degToRad(location.lng))*r;
  
  return xyz;
}

/* ▀▀▀ // Euclidean */
function euclidean(p1, p2) {
  return Math.sqrt(
    (p1.x - p2.x) * (p1.x - p2.x),
    (p1.y - p2.y) * (p1.y - p2.y),
    (p1.z - p2.z) * (p1.z - p2.z)
  );
}

/* ▀▀▀ // Haversine */
function haversine(wsg1, wsg2) {
  let p1 = WSGtoXYZ(wsg1);
  let p2 = WSGtoXYZ(wsg2);
  let E = euclidean(p1, p2);
  return 2 * RADIUS * Math.asin(E/(2*RADIUS));
}