Skip to content

Instantly share code, notes, and snippets.

View jackpordi's full-sized avatar

Jack Pordi jackpordi

View GitHub Profile
def sum_until_bad(n):
current = 1
result = 0
while current <= n:
result += current
result += 1
return result
def sum_until(n):
current = 1
result = 0
while current <= n:
result += current
current += 1
return result
class Counter {
constructor() {
this.count = 0;
}
increment() {
this.count++;
}
class Counter:
def __init__(self):
self.count = 0
def increment(self):
self.count += 1
def get_count(self):
return self.count
current_count = 0
def add_counter(x):
global current_count
current_count = current_count + 1
return x + current_count
print(add_counter(5)) # Prints 6
print(add_counter(5)) # Prints 7
const myArray = [1, 4, 9, 16];
const mappedArray = myArray.map( x => x * 2 );
// Same output as using timesTwo
console.log(mappedArray);
function myMap(list, func) {
output = [];
for (var i=0; i<list.length; i++){
output.push(
func(list[i])
);
}
return output;
}
const myArray = [1, 4, 9, 16];
function timesTwo(x) {
return x * 2;
}
// Pass the function to a map
const mappedArray = myArray.map(timesTwo);
function makeSoup() {
return Promise.all([
new Promise((reject, resolve) => {
chopCarrots();
chopOnions();
resolve();
}),
boilPot()
]).then(() => {
addCarrots();
function callbackHell() {
boilPot(() => {
addCarrots();
letPotKeepBoiling(
() => {
addOnions();
letPotKeepBoiling(
() => {
console.log("Your vegetable soup is ready!");
},