Skip to content

Instantly share code, notes, and snippets.

@secretgspot
Last active July 17, 2023 23:29
Show Gist options
  • Save secretgspot/68f62cb79935f68d180a4e0a4f3d35f3 to your computer and use it in GitHub Desktop.
Save secretgspot/68f62cb79935f68d180a4e0a4f3d35f3 to your computer and use it in GitHub Desktop.
/*
.___. .. . __ .___.._..__.. . __.
[__ | ||\ |/ ` | | | ||\ |(__
| |__|| \|\__. | _|_|__|| \|.__)
*/
/* ▀▀▀ // 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));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment