Skip to content

Instantly share code, notes, and snippets.

def merge(left, right)
return left if right[0].nil?
return right if left[0].nil?
if left[0] < right[0]
[left[0]] + merge(left[1..left.length], right)
else
[right[0]] + merge(left, right[1..right.length])
end
end
def fibs(n)
fib = [0, 1]
while fib.length < n
fib << fib[-1] + fib[-2]
end
fib.slice(0, n)
end
def fibs_rec(n)
return [0,1].slice(0, n) if n <= 2
@Dreniak
Dreniak / DistanceCalculator
Last active November 7, 2017 01:42
Damn! Why is it not working?
function calcule (origin, destination, unit) {
var xmlHttp = new XMLHttpRequest();
var key = 'ApiKey';
var outputFormat = 'json';
var url = `https://maps.googleapis.com/maps/api/distancematrix/${outputFormat}?&unit=${unit}&origins=${origin}&destinations=${destination}&key=${key}`;
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
console.log(xmlHttp.responseText);
} else {