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 Person(name) { | |
this.name = name; | |
this.greet = function () { | |
console.log("i am " + this.name); | |
} | |
}; | |
var jane = new Person("jane") | |
jane.greet() |
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 countWins(arr_of_champions, country) { | |
let wins = 0; // initialized to correct return type | |
/* | |
iterate through arr_of_objs | |
is obj.country = country? | |
if yes, wins++ | |
*/ | |
for (let obj of arr_of_champions) { |
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
/* | |
gasStation: Function | |
args: 3 | |
1. obj of objs: | |
{"gas_stationx": {"price": Number, "distance": Number}} | |
2. Number -> 0 <= x <= 60 | |
3. Float -> l/100k | |
return: String || undefined | |
behavior: | |
find the cheapest gas station for filling your tank. |
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
/* strategy | |
** constraint: use objects | |
0. declare variables, including object of vowls | |
1. convert string to object | |
2. delete all vowl properties | |
3. reconvert object to string | |
4. return string | |
*/ | |
function removeVowels (str){ // scaffold 1 |
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
// run this in pythontutor | |
// ----- 1 ----- | |
let jim = "jim"; | |
function printer(name) { | |
console.log(name); | |
}; |
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
// pythontutor this code | |
var cleancalc = { | |
lastResult: null, | |
add: function (arg1, arg2) { | |
return arg1 + arg2; | |
}, | |
operate: function (operation, arg1, arg2) { |
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
var app = { | |
db: {}, | |
next_id: 0, | |
create: function(newThing) { | |
// this.db[this.next_id] = newThing; | |
// this.next_id ++; | |
if(newThing !== ''){ | |
this.db[this.next_id] = newThing; | |
this.next_id ++; | |
console.log("THING WAS ADDED") |
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 simple_elevator(floor, button) { | |
let returner = 0; | |
let possible_result = Number(button) - floor; | |
// see if possible_result is allowed | |
// if it is, assign it to returner | |
return returner; | |
} |
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
// https://goo.gl/XDqbKF | |
function hoisted(){} | |
var not_hoisted = function(){} | |
var is_it_hoisted = function huh(){} | |
hoisted = 0 |
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
let arr = [4, 5, 6,] | |
let stringnum = "4" | |
let temp; | |
for (let num of arr) { | |
console.log(typeof (stringnum + num)) | |
} | |
// https://dmitripavlutin.com/javascriptss-addition-operator-demystified/ | |
// https://www.safaribooksonline.com/library/view/you-dont-know/9781491905159/ch04.html |