This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sum_until_bad(n): | |
current = 1 | |
result = 0 | |
while current <= n: | |
result += current | |
result += 1 | |
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sum_until(n): | |
current = 1 | |
result = 0 | |
while current <= n: | |
result += current | |
current += 1 | |
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Counter { | |
constructor() { | |
this.count = 0; | |
} | |
increment() { | |
this.count++; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Counter: | |
def __init__(self): | |
self.count = 0 | |
def increment(self): | |
self.count += 1 | |
def get_count(self): | |
return self.count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myArray = [1, 4, 9, 16]; | |
const mappedArray = myArray.map( x => x * 2 ); | |
// Same output as using timesTwo | |
console.log(mappedArray); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myMap(list, func) { | |
output = []; | |
for (var i=0; i<list.length; i++){ | |
output.push( | |
func(list[i]) | |
); | |
} | |
return output; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myArray = [1, 4, 9, 16]; | |
function timesTwo(x) { | |
return x * 2; | |
} | |
// Pass the function to a map | |
const mappedArray = myArray.map(timesTwo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function makeSoup() { | |
return Promise.all([ | |
new Promise((reject, resolve) => { | |
chopCarrots(); | |
chopOnions(); | |
resolve(); | |
}), | |
boilPot() | |
]).then(() => { | |
addCarrots(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function callbackHell() { | |
boilPot(() => { | |
addCarrots(); | |
letPotKeepBoiling( | |
() => { | |
addOnions(); | |
letPotKeepBoiling( | |
() => { | |
console.log("Your vegetable soup is ready!"); | |
}, |
NewerOlder