Skip to content

Instantly share code, notes, and snippets.

View viniciusarre's full-sized avatar
🏠
Working from home

Vinícius Eduardo da Silva Arré viniciusarre

🏠
Working from home
View GitHub Profile
# Better sollution
def main():
v = (1, 2, 3, 4, 5)
r = l = 1
print(bounded_ratio(v, l, r))
def bounded_ratio(a, l, r):
values = []
for i, v in enumerate(a):
values = values + [(i + 1) * x == v for x in range(l, r + 1)]
# Shorter solution
def bounded_ratio(a, l, r):
for i, v in enumerate(a):
for x in range(l, r + 1):
yield (i + 1) * x == v
v = (1, 2, 3, 4, 5)
r = l = 1
print(list(bounded_ratio(v, l, r)))
const boundedRatio = (a, l, r) => {
return a.map((v, i) => {
for (let x = l; x <= r; x++) {
return (i + 1) * x == v;
}
})
}
const v = [1, 2, 3, 4, 5]
const r = l = 1
console.log(boundedRatio(v, l, r))
@viniciusarre
viniciusarre / index.js
Created September 23, 2017 22:25
Contacting Partners
/*/We 'd like to contact partners with
offices within 100km of central London (coordinates 51.515419, -0.141099) to invite them out for a meal.
Write a NodeJS/JavaScript program that reads our list of partners (download partners.json here)
and outputs the company names and addresses of matching partners (with offices within 100km)
sorted by company name (ascending).
You can use the first formula from this Wikipedia article to calculate distance.
Don 't forget to convert degrees to radians! Your program should be fully tested too.
*/
const fs = require('fs');
const data = fs.readFileSync('partners.json');
@viniciusarre
viniciusarre / index.js
Last active September 23, 2017 22:29
Object Cloner
/*Write a function called deepClone which takes an object and creates a copy of it. e.g.
{name: "Paddy", address: {town: "Lerum", country: "Sweden"}} -> {name: "Paddy", address: {town: "Lerum", country: "Sweden"}}*/
function deepClone(obj){
var obj2 = obj;
return obj2;
}
var Paddy = {name: "Paddy", address: {town: "Lerum", country: "Sweden"}};