View testing-obj-and-function.js
function add(a, b) {
return a + b
}
let adder = {
result: 0,
add: function(a) {
this.result += a;
return this.result;
}
View bottle-management-evan.js
const bottleManagement = {
bottles: {},
nextId: 0,
addBottle: function (newBottle){
newBottle.key = this.nextId
this.bottles[this.nextId] = newBottle;
this.nextId++;
return this.nextID - 1;
},
getBottle: function(id){
View fp-bottleland.js
let bottles = {};
function new_bottle (total_vol, current_vol, liquid) {
return { total_vol, current_vol, liquid };
}
let bottles = {
DB: {},
name: "bottles",
nextID: 00,
View gist:985a95c0e52177921a21aa48dd81bf9f
function foo(x) { x = (typeof x != "undefined") ? x : 10; .. }
function foo(x = 10) { .. }
function foo(x,y,z) { .. }; foo.apply(null,[1,2,3]);
function foo(x,y,z) { .. }; foo(...[1,2,3]);
function foo() { var args = [].slice.call(arguments); .. }
function foo(...args) { .. }
var o = { x: 2, y: 3 }, x = o.x, y = o.y, z = (typeof o.z != "undefined") ? o.z : 10;
View README
as usual, run these in pythontutor
View README
some 'let' vs 'var' (block vs lexical) scoping examples
with a bit of context mixed in
run these in PythonTutor for greatest learning
View strategy-inference
function (num1, num2)
2: declare necessary variables
6: type validation
9: convert args to practical data type
View README
Loops
behavioral specifications:
(think of an ideal use case for a loop)
- eating, you do it everyday
weekly meal eater
code specs
args: 1
View README
Greetings:
behavioral specifications:
- cases are mutually exclusive
if it's morning, say good morning
from 0001 to 1200
if it's afternoon, say good afternoon
from 1201 to 1800
if it's evening, say good evening
from 1801 to 0000
View fp-water-bottle.js
const bottle_size = 1000;
let bottle_fullness = 600;
function read_water_level(bottle_fullness) {
console.log(bottle_fullness)
};
function drink_water(bottle_fullness, thrist_score) { // one unit of water quenches 1 thrist point
let new_fullness = 0;
let remaining_thirst = 0;