From d4fe6a041da60da51052e8d8c04a368298796116 Mon Sep 17 00:00:00 2001 From: Ronan MacParland Date: Mon, 15 Jan 2018 17:14:31 -0500 Subject: [PATCH 1/4] add test --- test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test.txt diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..e69de29 From edaafe847690225fb7af429d592b5886fd9f2494 Mon Sep 17 00:00:00 2001 From: Ronan MacParland Date: Mon, 15 Jan 2018 17:19:03 -0500 Subject: [PATCH 2/4] npm install and Bind SRC complete --- package-lock.json | 326 +++++++++++++++++++++++++++++++++++++++++++ src/bind/problem1.js | 3 +- src/bind/problem2.js | 4 +- 3 files changed, 330 insertions(+), 3 deletions(-) create mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..f09c238 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,326 @@ +{ + "name": "javascript-fundamentals", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "assertion-error": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", + "dev": true + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "brace-expansion": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", + "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", + "dev": true, + "requires": { + "balanced-match": "1.0.0", + "concat-map": "0.0.1" + } + }, + "browser-stdout": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.0.tgz", + "integrity": "sha1-81HTKWnTL6XXpVZxVCY9korjvR8=", + "dev": true + }, + "chai": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-3.5.0.tgz", + "integrity": "sha1-TQJjewZ/6Vi9v906QOxW/vc3Mkc=", + "dev": true, + "requires": { + "assertion-error": "1.1.0", + "deep-eql": "0.1.3", + "type-detect": "1.0.0" + } + }, + "chai-spies": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/chai-spies/-/chai-spies-0.7.1.tgz", + "integrity": "sha1-ND2Z9RJEIS6LF+ZLk5lv97LCqbE=", + "dev": true + }, + "commander": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.9.0.tgz", + "integrity": "sha1-nJkJQXbhIkDLItbFFGCYQA/g99Q=", + "dev": true, + "requires": { + "graceful-readlink": "1.0.1" + } + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "debug": { + "version": "2.6.8", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", + "integrity": "sha1-5zFTHKLt4n0YgiJCfaF4IdaP9Pw=", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "deep-eql": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-0.1.3.tgz", + "integrity": "sha1-71WKyrjeJSBs1xOQbXTlaTDrafI=", + "dev": true, + "requires": { + "type-detect": "0.1.1" + }, + "dependencies": { + "type-detect": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-0.1.1.tgz", + "integrity": "sha1-C6XsKohWQORw6k6FBZcZANrFiCI=", + "dev": true + } + } + }, + "diff": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-3.2.0.tgz", + "integrity": "sha1-yc45Okt8vQsFinJck98pkCeGj/k=", + "dev": true + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "dev": true + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, + "glob": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.1.tgz", + "integrity": "sha1-gFIR3wT6rxxjo2ADBs31reULLsg=", + "dev": true, + "requires": { + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "graceful-readlink": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz", + "integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=", + "dev": true + }, + "growl": { + "version": "1.9.2", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.9.2.tgz", + "integrity": "sha1-Dqd0NxXbjY3ixe3hd14bRayFwC8=", + "dev": true + }, + "has-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-1.0.0.tgz", + "integrity": "sha1-nZ55MWXOAXoA8AQYxD+UKnsdEfo=", + "dev": true + }, + "he": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", + "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", + "dev": true + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "requires": { + "once": "1.4.0", + "wrappy": "1.0.2" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true + }, + "json3": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/json3/-/json3-3.3.2.tgz", + "integrity": "sha1-PAQ0dD35Pi9cQq7nsZvLSDV19OE=", + "dev": true + }, + "lodash._baseassign": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz", + "integrity": "sha1-jDigmVAPIVrQnlnxci/QxSv+Ck4=", + "dev": true, + "requires": { + "lodash._basecopy": "3.0.1", + "lodash.keys": "3.1.2" + } + }, + "lodash._basecopy": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz", + "integrity": "sha1-jaDmqHbPNEwK2KVIghEd08XHyjY=", + "dev": true + }, + "lodash._basecreate": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash._basecreate/-/lodash._basecreate-3.0.3.tgz", + "integrity": "sha1-G8ZhYU2qf8MRt9A78WgGoCE8+CE=", + "dev": true + }, + "lodash._getnative": { + "version": "3.9.1", + "resolved": "https://registry.npmjs.org/lodash._getnative/-/lodash._getnative-3.9.1.tgz", + "integrity": "sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=", + "dev": true + }, + "lodash._isiterateecall": { + "version": "3.0.9", + "resolved": "https://registry.npmjs.org/lodash._isiterateecall/-/lodash._isiterateecall-3.0.9.tgz", + "integrity": "sha1-UgOte6Ql+uhCRg5pbbnPPmqsBXw=", + "dev": true + }, + "lodash.create": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/lodash.create/-/lodash.create-3.1.1.tgz", + "integrity": "sha1-1/KEnw29p+BGgruM1yqwIkYd6+c=", + "dev": true, + "requires": { + "lodash._baseassign": "3.2.0", + "lodash._basecreate": "3.0.3", + "lodash._isiterateecall": "3.0.9" + } + }, + "lodash.isarguments": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz", + "integrity": "sha1-L1c9hcaiQon/AGY7SRwdM4/zRYo=", + "dev": true + }, + "lodash.isarray": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/lodash.isarray/-/lodash.isarray-3.0.4.tgz", + "integrity": "sha1-eeTriMNqgSKvhvhEqpvNhRtfu1U=", + "dev": true + }, + "lodash.keys": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/lodash.keys/-/lodash.keys-3.1.2.tgz", + "integrity": "sha1-TbwEcrFWvlCgsoaFXRvQsMZWCYo=", + "dev": true, + "requires": { + "lodash._getnative": "3.9.1", + "lodash.isarguments": "3.1.0", + "lodash.isarray": "3.0.4" + } + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "1.1.8" + } + }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + } + }, + "mocha": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-3.5.3.tgz", + "integrity": "sha512-/6na001MJWEtYxHOV1WLfsmR4YIynkUEhBwzsb+fk2qmQ3iqsi258l/Q2MWHJMImAcNpZ8DEdYAK72NHoIQ9Eg==", + "dev": true, + "requires": { + "browser-stdout": "1.3.0", + "commander": "2.9.0", + "debug": "2.6.8", + "diff": "3.2.0", + "escape-string-regexp": "1.0.5", + "glob": "7.1.1", + "growl": "1.9.2", + "he": "1.1.1", + "json3": "3.3.2", + "lodash.create": "3.1.1", + "mkdirp": "0.5.1", + "supports-color": "3.1.2" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "requires": { + "wrappy": "1.0.2" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, + "supports-color": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-3.1.2.tgz", + "integrity": "sha1-cqJiiU2dQIuVbKBf83su2KbiotU=", + "dev": true, + "requires": { + "has-flag": "1.0.0" + } + }, + "type-detect": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-1.0.0.tgz", + "integrity": "sha1-diIXzAbbJY7EiQihKY6LlRIejqI=", + "dev": true + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true + } + } +} diff --git a/src/bind/problem1.js b/src/bind/problem1.js index da0b2d6..9115e4b 100644 --- a/src/bind/problem1.js +++ b/src/bind/problem1.js @@ -2,6 +2,7 @@ var bob = {name: "Bob"}; function greet() { return "I'm " + this.name; } -// bind greet to bob + +var greet = greet.bind(bob); module.exports = greet; \ No newline at end of file diff --git a/src/bind/problem2.js b/src/bind/problem2.js index 079a343..aa26f93 100644 --- a/src/bind/problem2.js +++ b/src/bind/problem2.js @@ -1,9 +1,9 @@ // Fix all the errors in this program var dog = {breed: "schnitzel"}; function greet() { - return "I'm a " + this.bred; + return "I'm a " + this.breed; } -greet.bind(dog); +var greet = greet.bind(dog); module.exports = greet; \ No newline at end of file From 2f4f289a81bee3565249ab3a708e540647c07a56 Mon Sep 17 00:00:00 2001 From: Ronan MacParland Date: Mon, 15 Jan 2018 20:50:15 -0500 Subject: [PATCH 3/4] day 6 done --- .../anonymous-functions/problem1.txt | 3 ++ .../anonymous-functions/problem2.txt | 4 ++- .../anonymous-functions/problem3.txt | 3 ++ .../anonymous-functions/problem4.txt | 4 ++- .../anonymous-functions/problem5.txt | 5 ++- paperproblems/return/problem1.txt | 2 ++ paperproblems/this/problem1.txt | 1 + paperproblems/this/problem2.txt | 1 + paperproblems/this/problem3.txt | 1 + paperproblems/this/problem4.txt | 4 ++- src/__proto__/problem1.js | 5 +-- src/anonymous-functions/problem1.js | 9 ++++-- src/exceptions/problem1.js | 31 ++++++++++++++++++- src/return/problem1.js | 13 +++----- src/this/problem1.js | 4 +++ 15 files changed, 71 insertions(+), 19 deletions(-) diff --git a/paperproblems/anonymous-functions/problem1.txt b/paperproblems/anonymous-functions/problem1.txt index 08e09e7..91ac1c0 100644 --- a/paperproblems/anonymous-functions/problem1.txt +++ b/paperproblems/anonymous-functions/problem1.txt @@ -5,4 +5,7 @@ function greet(x) { console.log("hello " + x); } +var greet = function(x) {console.log("hello " + x);} +var bob = "bob" + greet(bob); \ No newline at end of file diff --git a/paperproblems/anonymous-functions/problem2.txt b/paperproblems/anonymous-functions/problem2.txt index 7cfb344..a74380c 100644 --- a/paperproblems/anonymous-functions/problem2.txt +++ b/paperproblems/anonymous-functions/problem2.txt @@ -3,7 +3,7 @@ In other words, replace all the function definitions with anonymous functions The final program should be on a single line -function greet(x) { +function (x) { console.log("hello " + x); } @@ -12,3 +12,5 @@ function call(f) { } call(greet); + +(function (x) {console.log("hello " + x);})("bob") \ No newline at end of file diff --git a/paperproblems/anonymous-functions/problem3.txt b/paperproblems/anonymous-functions/problem3.txt index 5d8a0fc..571402e 100644 --- a/paperproblems/anonymous-functions/problem3.txt +++ b/paperproblems/anonymous-functions/problem3.txt @@ -10,3 +10,6 @@ function call(f) { } call(greet); + + +(function (x, y) {console.log("hello " + x + " " + y)})("Bob", "Dole") \ No newline at end of file diff --git a/paperproblems/anonymous-functions/problem4.txt b/paperproblems/anonymous-functions/problem4.txt index 689d724..2d86302 100644 --- a/paperproblems/anonymous-functions/problem4.txt +++ b/paperproblems/anonymous-functions/problem4.txt @@ -10,4 +10,6 @@ function twice(f) { f("mary"); } -twice(greet); \ No newline at end of file +twice(greet); + +twice(function(x){console.log("hello " + x);}) \ No newline at end of file diff --git a/paperproblems/anonymous-functions/problem5.txt b/paperproblems/anonymous-functions/problem5.txt index 2d69a4d..8ad3aa9 100644 --- a/paperproblems/anonymous-functions/problem5.txt +++ b/paperproblems/anonymous-functions/problem5.txt @@ -16,4 +16,7 @@ function soften(f) { var softAskOnADate = soften(askOnADate); console.log(softAskOnADate("Eric")); -console.log(softAskOnADate("Bob")); +console.log(softAskOnADate("Bob")); + +Bob = I do +Eric = Maybe diff --git a/paperproblems/return/problem1.txt b/paperproblems/return/problem1.txt index fed99b8..2f8f3d5 100644 --- a/paperproblems/return/problem1.txt +++ b/paperproblems/return/problem1.txt @@ -7,3 +7,5 @@ function f() { console.log(f()); +5 + diff --git a/paperproblems/this/problem1.txt b/paperproblems/this/problem1.txt index 7212ac6..4720815 100644 --- a/paperproblems/this/problem1.txt +++ b/paperproblems/this/problem1.txt @@ -9,3 +9,4 @@ function foo() { var obj = {bar: foo, baz: 8}; obj.bar(); +8 \ No newline at end of file diff --git a/paperproblems/this/problem2.txt b/paperproblems/this/problem2.txt index 1144503..e01715e 100644 --- a/paperproblems/this/problem2.txt +++ b/paperproblems/this/problem2.txt @@ -10,3 +10,4 @@ var obj = { var g = obj.bar; g(); +UNDEFINED CONTEXT CHANGED - THIS = UNDEFINED \ No newline at end of file diff --git a/paperproblems/this/problem3.txt b/paperproblems/this/problem3.txt index dcfda4d..2fd165a 100644 --- a/paperproblems/this/problem3.txt +++ b/paperproblems/this/problem3.txt @@ -15,3 +15,4 @@ var obj2 = { obj2.bar = obj.bar; obj2.bar(); +ANSWER IS 12 - OBJ.BAR IS SAME AS OBJ2.BAR \ No newline at end of file diff --git a/paperproblems/this/problem4.txt b/paperproblems/this/problem4.txt index d7a9ebd..bc18df3 100644 --- a/paperproblems/this/problem4.txt +++ b/paperproblems/this/problem4.txt @@ -11,4 +11,6 @@ function f(g) { console.log(g(4)); } -f(obj.bar); \ No newline at end of file +f(obj.bar); + +ANSWER IS UNDEFINED - CONTEXT CHANGED \ No newline at end of file diff --git a/src/__proto__/problem1.js b/src/__proto__/problem1.js index 820a78d..f84a164 100644 --- a/src/__proto__/problem1.js +++ b/src/__proto__/problem1.js @@ -1,6 +1,7 @@ // Make parent the __proto__ of child -var parent = {x: 5, y: 6, z: 8}; -var child = {x : 10}; +var parent= {x: 5, y: 6, z: 8}; +var child = {x : 10, __proto__:parent}; + module.exports = {parent, child} \ No newline at end of file diff --git a/src/anonymous-functions/problem1.js b/src/anonymous-functions/problem1.js index ab1384c..013941d 100644 --- a/src/anonymous-functions/problem1.js +++ b/src/anonymous-functions/problem1.js @@ -1,7 +1,10 @@ // fix all the errors -function c(g, h) { - var x = g(6); - var y = h(8); +var y = 6; +var x = 8; + +var c = function c(g, h) { + var x = g(y); + var y = h(x); return [x, y]; } diff --git a/src/exceptions/problem1.js b/src/exceptions/problem1.js index f54c8f8..4dc59e4 100644 --- a/src/exceptions/problem1.js +++ b/src/exceptions/problem1.js @@ -1,22 +1,51 @@ function first(arr) { // Throw an exception if the array has no elements // Otherwise return the first element + if(arr.length === 0) {throw new Error ("error");} + + return arr[0]; + } function detective(i) { function suspect(i) { if(i * 7 % 3 == 0) throw new Error("Bad i!"); } + + try { + + suspect(i); + + } catch (error) { + + return "something fishy"; + + } // detective checks to see if the suspect throws an exception on input i. // Returns "everything ok" if the suspect doesn't. + return "everything ok"; // Returns "something fishy" if the suspect does. } function assignFlight(name) { var flightNumber = ((name.length * 7) % 20) + "0"; var terrorSuspects = ["bob", "eric", "susie"]; + + for (var x in terrorSuspects) { + if (terrorSuspects[x] === name) { + throw new Error("found a terrorist"); + } + } + + return flightNumber; // if the name is a terror suspect, throw an exception - // Otherwise, return the flight number + // for(var x = 0; x 10) { return "hello"; - } else if(x > 5) { + } else if(x > 5){ return "goodbye"; - } else { - return undefined; - } + } } -module.exports = f; // Don't delete this line but remove this comment. - +module.exports = f; diff --git a/src/this/problem1.js b/src/this/problem1.js index b7b2740..dc2d866 100644 --- a/src/this/problem1.js +++ b/src/this/problem1.js @@ -1,5 +1,9 @@ 'use strict'; + function whatsMyAgeAgain() { + var age = 20; + if (this === undefined){return 18} + return this.age; // returns this.age unless this is not defined. If this is not defined, return 18 } From 15fd718fe924ef8c2116a07e794fc652a64dfcc1 Mon Sep 17 00:00:00 2001 From: Ronan MacParland Date: Thu, 18 Jan 2018 17:35:13 -0500 Subject: [PATCH 4/4] done all excersizes --- paperproblems/array-functions/problem1.txt | 5 +- paperproblems/array-functions/problem2.txt | 4 +- paperproblems/array-functions/problem3.txt | 4 +- paperproblems/array-functions/problem4.txt | 4 +- paperproblems/arrow-functions/problem1.txt | 14 ++++++ paperproblems/callbacks/problem1.txt | 2 +- paperproblems/callbacks/problem2.txt | 8 ++- paperproblems/classes/problem1.txt | 1 + paperproblems/classes/problem2.txt | 6 +++ .../conditional-operator/problem1.txt | 4 +- .../constructor-functions/problem1.txt | 4 +- .../constructor-functions/problem2.txt | 4 +- .../constructor-functions/problem3.txt | 7 ++- .../constructor-functions/problem4.txt | 7 ++- .../constructor-functions/problem5.txt | 28 +++++++++-- paperproblems/inheritance/problem2.txt | 18 +++++++ paperproblems/variable-scoping/problem1.txt | 3 ++ paperproblems/variable-scoping/problem2.txt | 5 +- paperproblems/variable-scoping/problem3.txt | 6 ++- paperproblems/variable-scoping/problem4.txt | 8 ++- src/array-functions/problem1.js | 50 +++++++++++++++++++ src/arrow-functions/problem1.js | 2 +- src/arrow-functions/problem2.js | 8 +-- src/callbacks/problem1.js | 6 +-- src/classes/problem1.js | 15 ++++-- src/conditional-operator/problem1.js | 22 ++------ src/conditional-operator/problem2.js | 12 +++-- src/constructor-functions/problem1.js | 9 ++++ src/inheritance/problem1.js | 38 ++++++++------ src/inheritance/problem2.js | 16 ++++-- src/variable-scoping/problem1.js | 3 +- test.txt | 0 32 files changed, 250 insertions(+), 73 deletions(-) delete mode 100644 test.txt diff --git a/paperproblems/array-functions/problem1.txt b/paperproblems/array-functions/problem1.txt index 8e97911..47ee6be 100644 --- a/paperproblems/array-functions/problem1.txt +++ b/paperproblems/array-functions/problem1.txt @@ -13,4 +13,7 @@ var dogs = animals.filter( function(animal) {return animal.species === 'dog';}); -console.log(dogs.length); \ No newline at end of file + +console.log(dogs.length); + +2 \ No newline at end of file diff --git a/paperproblems/array-functions/problem2.txt b/paperproblems/array-functions/problem2.txt index e9050e5..ade48ce 100644 --- a/paperproblems/array-functions/problem2.txt +++ b/paperproblems/array-functions/problem2.txt @@ -13,4 +13,6 @@ var letterN = animals.filter(function(animal) { return animal.name !== undefined && animal.name[0] === 'N' }); -console.log(letterN[0].name); \ No newline at end of file +console.log(letterN[0].name); + +Nacho \ No newline at end of file diff --git a/paperproblems/array-functions/problem3.txt b/paperproblems/array-functions/problem3.txt index e1182ab..e98b8ca 100644 --- a/paperproblems/array-functions/problem3.txt +++ b/paperproblems/array-functions/problem3.txt @@ -10,4 +10,6 @@ var animals = [ var animalNames = animals.map( function(animal) {return animal.name}); -console.log(animalNames.join()); \ No newline at end of file +console.log(animalNames.join()); + +Nacho,Ramses,Flufftail,Popcorn,Neckbeard,'' \ No newline at end of file diff --git a/paperproblems/array-functions/problem4.txt b/paperproblems/array-functions/problem4.txt index 8b933aa..17a7193 100644 --- a/paperproblems/array-functions/problem4.txt +++ b/paperproblems/array-functions/problem4.txt @@ -11,8 +11,8 @@ function isDog(animal) { return animal.species === 'dog'; } -animals.some(isDog) -animals.every(isDog) +animals.some(isDog) true +animals.every(isDog) false diff --git a/paperproblems/arrow-functions/problem1.txt b/paperproblems/arrow-functions/problem1.txt index 7338e61..e02e13e 100644 --- a/paperproblems/arrow-functions/problem1.txt +++ b/paperproblems/arrow-functions/problem1.txt @@ -3,17 +3,31 @@ For each of the following expressions: - If it doesn't have a syntax error, what are the probable input and output types of the function? a) x => x + 1 +yes. typo. returns x +1 +x => x + 1 b) x, y => x * y +(x,y) => x * y (returns x * y) + c) x => { x * 2 } +x => x * 2 (returns x * 2 ) + d) (x, z) => {console.log(z); return x * z} +(x, z) => {console.log(z); return x * z} + e) x => console.log(z); return x * z +x => {console.log(z); return x * z} + f) (x) => x * 2 +None + e) () => console.log("hello") + + When you're done, check all your answers in the developer console. \ No newline at end of file diff --git a/paperproblems/callbacks/problem1.txt b/paperproblems/callbacks/problem1.txt index 63df256..584e63f 100644 --- a/paperproblems/callbacks/problem1.txt +++ b/paperproblems/callbacks/problem1.txt @@ -12,4 +12,4 @@ function h() { setTimeout(f, 1000); } -setTimeout(h, 200); \ No newline at end of file +setTimeout(h, 2000); \ No newline at end of file diff --git a/paperproblems/callbacks/problem2.txt b/paperproblems/callbacks/problem2.txt index 1ee06dd..584e63f 100644 --- a/paperproblems/callbacks/problem2.txt +++ b/paperproblems/callbacks/problem2.txt @@ -4,8 +4,12 @@ function g() { console.log("Hello!") } +function f() { + setTimeout(g, 500); +} + function h() { - setInterval(g, 1000); + setTimeout(f, 1000); } -setInterval(h, 1000); \ No newline at end of file +setTimeout(h, 2000); \ No newline at end of file diff --git a/paperproblems/classes/problem1.txt b/paperproblems/classes/problem1.txt index 9fbc41e..cc6e601 100644 --- a/paperproblems/classes/problem1.txt +++ b/paperproblems/classes/problem1.txt @@ -12,3 +12,4 @@ class Dog { } var someDog = new Dog("schnitzel", 2, "male"); +done \ No newline at end of file diff --git a/paperproblems/classes/problem2.txt b/paperproblems/classes/problem2.txt index 60891b1..302b3f1 100644 --- a/paperproblems/classes/problem2.txt +++ b/paperproblems/classes/problem2.txt @@ -1,18 +1,24 @@ What is the output of this program? class Person { + constructor(age, name, salary) { this.age = age; this.name = name; this.salary = salary; + } increaseSalary(amount) { + console.log("Yay!"); this.salary = this.salary + amount; + } toString() { + return "My name is " + this.name + "and I'm " + this.age + " and I make " + this.salary; + } } diff --git a/paperproblems/conditional-operator/problem1.txt b/paperproblems/conditional-operator/problem1.txt index fabd9e8..18be0ff 100644 --- a/paperproblems/conditional-operator/problem1.txt +++ b/paperproblems/conditional-operator/problem1.txt @@ -4,4 +4,6 @@ function f(x) { return x < 5 ? 3 : x > 8 ? 4 : x == 6 ? 12 : 9; } -console.log(f(5)); \ No newline at end of file +console.log(f(5)); + +Returns 9 \ No newline at end of file diff --git a/paperproblems/constructor-functions/problem1.txt b/paperproblems/constructor-functions/problem1.txt index bd77a77..f106f03 100644 --- a/paperproblems/constructor-functions/problem1.txt +++ b/paperproblems/constructor-functions/problem1.txt @@ -12,4 +12,6 @@ function Person(name, age) { } } -var bob = new Person("Bob", 30); \ No newline at end of file +var bob = new Person("Bob", 30); + +Done. \ No newline at end of file diff --git a/paperproblems/constructor-functions/problem2.txt b/paperproblems/constructor-functions/problem2.txt index 4cb7dd9..0fb0cdb 100644 --- a/paperproblems/constructor-functions/problem2.txt +++ b/paperproblems/constructor-functions/problem2.txt @@ -12,4 +12,6 @@ var bob = new Person("Bob", 30); Person.prototype.leave = function() {return this.name + " is leaving";} -bob.leave(); \ No newline at end of file +bob.leave(); + +bob is leaving \ No newline at end of file diff --git a/paperproblems/constructor-functions/problem3.txt b/paperproblems/constructor-functions/problem3.txt index 2c875ee..fd0eeb7 100644 --- a/paperproblems/constructor-functions/problem3.txt +++ b/paperproblems/constructor-functions/problem3.txt @@ -16,4 +16,9 @@ Person.prototype.salary = Person.prototype.salary + 300; Person.__proto__.salary = Person.__proto__.salary + 400; bob.salary = bob.salary + 50; -console.log(bob.salary); \ No newline at end of file +console.log(bob.salary); + +Functions do not have a __proto__ +Bob has a proto. + +40 450 \ No newline at end of file diff --git a/paperproblems/constructor-functions/problem4.txt b/paperproblems/constructor-functions/problem4.txt index 10d57df..84a40b0 100644 --- a/paperproblems/constructor-functions/problem4.txt +++ b/paperproblems/constructor-functions/problem4.txt @@ -8,8 +8,11 @@ function Person(name, age) { } } -var bob = Person("Bob", 30); +var bob = new Person("Bob", 30); bob.name = bob.name + " Dole"; -bob.greet(); \ No newline at end of file +bob.greet(); + +TYPO - "new" +Hi my name is bob Dole \ No newline at end of file diff --git a/paperproblems/constructor-functions/problem5.txt b/paperproblems/constructor-functions/problem5.txt index f47e2b8..846e80f 100644 --- a/paperproblems/constructor-functions/problem5.txt +++ b/paperproblems/constructor-functions/problem5.txt @@ -1,12 +1,32 @@ Rewrite this program so that it does't use the new keyword. The program must be equivalent in every other way. +var newPerson = {}; + +function Person(name, age) { + var ret = {} + ret.name = name; + ret.age = age; + ret.greet = function() { + console.log("Hello my name is " + this.name); + } + + return ret; +} + +var bob = newPerson("Bob", 30); + +var newPerson = {}; + function Person(name, age) { - this.name = name; - this.age = age; - this.greet = function() { + var ret = { + name : name; + age : age; + greet : function() { console.log("Hello my name is " + this.name); } + ret.__proto__ = Person.prototype; + return ret; } -var bob = Person("Bob", 30); \ No newline at end of file +var bob = newPerson("Bob", 30); \ No newline at end of file diff --git a/paperproblems/inheritance/problem2.txt b/paperproblems/inheritance/problem2.txt index f9d6898..d004c68 100644 --- a/paperproblems/inheritance/problem2.txt +++ b/paperproblems/inheritance/problem2.txt @@ -11,3 +11,21 @@ class Shape { this.area() + " and perimeter " + this.perimeter(); } } + +class Rectangle extends Shape { + constructor(size){ + super("rectangle"); + this.size = size; + } + + area(){ + return this.size * this.size; + } + + perimeter(){ + return this.size * 4; + } +} + +var x = new Rectangle(5); +x.toString(5); \ No newline at end of file diff --git a/paperproblems/variable-scoping/problem1.txt b/paperproblems/variable-scoping/problem1.txt index 281bdd6..ee234ac 100644 --- a/paperproblems/variable-scoping/problem1.txt +++ b/paperproblems/variable-scoping/problem1.txt @@ -9,3 +9,6 @@ function f() { f(); f(); + +2 +4 \ No newline at end of file diff --git a/paperproblems/variable-scoping/problem2.txt b/paperproblems/variable-scoping/problem2.txt index eb70c9d..9633cdf 100644 --- a/paperproblems/variable-scoping/problem2.txt +++ b/paperproblems/variable-scoping/problem2.txt @@ -7,4 +7,7 @@ function f() { } f(); -f(); \ No newline at end of file +f(); + +2 +2 diff --git a/paperproblems/variable-scoping/problem3.txt b/paperproblems/variable-scoping/problem3.txt index ba8ada5..8802c9e 100644 --- a/paperproblems/variable-scoping/problem3.txt +++ b/paperproblems/variable-scoping/problem3.txt @@ -11,4 +11,8 @@ function f() { f(); f(); -console.log(y); \ No newline at end of file +console.log(y); + +7 +9 +3 \ No newline at end of file diff --git a/paperproblems/variable-scoping/problem4.txt b/paperproblems/variable-scoping/problem4.txt index 2294b2e..a700810 100644 --- a/paperproblems/variable-scoping/problem4.txt +++ b/paperproblems/variable-scoping/problem4.txt @@ -1,12 +1,16 @@ Which variables are in scope on the indicated line? var x = 5; + function f() { var y = 8; + function g() { var z = 10; + function h() { var p = "hello"; + function k() { var b = "boom"; } @@ -14,4 +18,6 @@ function f() { } } -} \ No newline at end of file +} + +x,p,z,y \ No newline at end of file diff --git a/src/array-functions/problem1.js b/src/array-functions/problem1.js index 06bc426..6e54523 100644 --- a/src/array-functions/problem1.js +++ b/src/array-functions/problem1.js @@ -1,20 +1,62 @@ function removeEvens(lst) { + + var newLst = []; + + for (var x = 0; x < lst.length; x++) { + if (lst[x] % 2 !== 0) { + newLst.push(lst[x]) + + } + + } + + return newLst; + // lst is an array of numbers // Returns a new list with all the even numbers of lst removed } function keepLong(lst) { + + var newArray = [] + + for (var x = 0; x < lst.length; x++){ + if(lst[x].length > 5){ + newArray.push(lst[x]) + } + + } + return newArray; // lst is an array of strings // Returns a new list with all the elements of lst that are length greater than 5 } function greet(lst) { + var newArr = [] + var hello = "Hello "; + for (let index = 0; index < lst.length; index++) { + newArr.push(hello.concat(lst[index])); + } + + return newArr // lst is an array of strings // Adds "Hello " to every element of greet // For example: greet(["bob", "eric"]) returns ["Hello bob", "Hello eric"] } function greetLong(lst) { + + var longLst = []; + var hello = "Hello " + + for (let index = 0; index < lst.length; index++) { + + if (lst[index].length >=4 ) { + longLst.push(hello + lst[index]) + } + } + + return longLst; // lst is an array of strings // Only greet people who's names have length at least 4. // Otherwise ignore them completely. @@ -22,6 +64,14 @@ function greetLong(lst) { } function allLong(lst) { + + for (let index = 0; index < lst.length; index++) { + if (lst[index].length >= 5){ + true + } else {return false} + } + + return true; // lst is an array of strings // Returns true if every element of lst is of length at least 5. Otherwise returns false. } diff --git a/src/arrow-functions/problem1.js b/src/arrow-functions/problem1.js index 5c0873a..bad3d0a 100644 --- a/src/arrow-functions/problem1.js +++ b/src/arrow-functions/problem1.js @@ -6,7 +6,7 @@ function c(g, h) { } function t() { - return c( x => return y + 2, (x,y) => return x + y); + return c(x => y + 2, (x,y) => x + y) } module.exports = t diff --git a/src/arrow-functions/problem2.js b/src/arrow-functions/problem2.js index 1ae3fdb..bd9569d 100644 --- a/src/arrow-functions/problem2.js +++ b/src/arrow-functions/problem2.js @@ -1,9 +1,11 @@ // Convert all the arrow functions to normal anonymous functions // There should be no arrows by the end -var x = x => x + 1; -var y = (x, y) => x + y; -var z = x => {var y = (x * 7) % 2; return y * 2}; +var x = function(y){return y + 1;} +var y = function(x, y) {return x + y;} +var z = function (x){ + var y = (x * 7) % 2; + return y * 2}; module.exports = {x, y, z}; diff --git a/src/callbacks/problem1.js b/src/callbacks/problem1.js index 0e8eb76..3a047d3 100644 --- a/src/callbacks/problem1.js +++ b/src/callbacks/problem1.js @@ -1,7 +1,7 @@ // Fix all the errors. It should print hello after 1 second -function shout(x) { - console.log(x.toUppercase()); +function shout() { + console.log("hello"); } -SetTimeout(shout("hello"), 1); \ No newline at end of file +setTimeout(shout, 1000); \ No newline at end of file diff --git a/src/classes/problem1.js b/src/classes/problem1.js index 8e1bcc9..58a337c 100644 --- a/src/classes/problem1.js +++ b/src/classes/problem1.js @@ -1,7 +1,16 @@ class Dog { - // Dog has a constructor with three arguments (in this order): age, name and breed - // Dog has three attributes: age, name and breed - // Dog has a method bark, which returns a string + + constructor(age, name, breed){ + + this.age = age; + this.name = name; + this.breed = breed; + } + + bark(){ + return "woof!"; + } + } module.exports = Dog; \ No newline at end of file diff --git a/src/conditional-operator/problem1.js b/src/conditional-operator/problem1.js index af6e31d..e385f02 100644 --- a/src/conditional-operator/problem1.js +++ b/src/conditional-operator/problem1.js @@ -1,23 +1,11 @@ -//Remove the if statements from these functions. -//Replace them with the conditional operator - -function desirability(x) { - if(x == 'Brad Pitt') { - return "very desirable"; - } else { - return "not so desirable"; - } +function desirability(x) { + return x == 'Brad Pitt' ? "very desirable" : "not so desirable"; } -function broadenHorizon(x) { - if(x == 'Brad Pitt') { - return "very desirable"; - } else if(x == 'Angelina Jolie') { - return "also desirable"; - } else { - return "not desirable"; - } + +function broadenHorizon(x) { + return (x === 'Brad Pitt') ? ("very desirable") : x == 'Angelina Jolie' ? "also desirable" : "not desirable"; } module.exports = {desirability, broadenHorizon} \ No newline at end of file diff --git a/src/conditional-operator/problem2.js b/src/conditional-operator/problem2.js index 2dd85bf..1866bb1 100644 --- a/src/conditional-operator/problem2.js +++ b/src/conditional-operator/problem2.js @@ -1,12 +1,14 @@ -// Remove the conditional operator from these functions -// Replace them with if statements -function iLike(x) { - return x == 'chinese food' ? true : false; + +function iLike(x) { + if (x == 'chinese food') {return true} + else {return false}; } function iLikeLessPicky(x) { - return x == 'chinese food' ? true : x == 'french food' ? true : false; + if (x == 'chinese food'){return true} + else if (x == 'french food') {return true} + else {return false}; } module.exports = {iLike, iLikeLessPicky}; \ No newline at end of file diff --git a/src/constructor-functions/problem1.js b/src/constructor-functions/problem1.js index b39887c..58e3cdf 100644 --- a/src/constructor-functions/problem1.js +++ b/src/constructor-functions/problem1.js @@ -1,2 +1,11 @@ // Add a function to all arrays called isNotEmpty // isNotEmpty returns true is the array is empty, false otherwise + + +Array.prototype.isNotEmpty = function () { + if (this.length === 0) { + return false; + } + return true; +}; + diff --git a/src/inheritance/problem1.js b/src/inheritance/problem1.js index 71e66b5..545cc3a 100644 --- a/src/inheritance/problem1.js +++ b/src/inheritance/problem1.js @@ -1,26 +1,36 @@ class Shape { + constructor(){ + + } toString() { return "This shape has an area of " + this.area() + " and perimeter " + this.perimeter(); } } -class Rectangle { +class Rectangle extends Shape { - // A rectangle is a shape - // Every rectangle has a width and a height - // Implement the constructor - // Implement the area and perimeter methods - // The constructor has two arguments: width and height -} + constructor(w,h){ + super(); + this.width = w; + this.height = h; + } + + area(){ + return this.width * this.height; + } + + perimeter(){ + return (this.width * 2 + this.height * 2); + } -class Square { - // A square is a rectangle - // Every square has a width and a height - // The height and width of a square are always the same - // Implement the constructor - // Do not implement the area and perimeter methods. They should be inherited from Rectangle - // The constructor has one argument } +class Square extends Rectangle { + + constructor (h){ + super (h,h); + +} +} module.exports = {Shape, Rectangle, Square}; \ No newline at end of file diff --git a/src/inheritance/problem2.js b/src/inheritance/problem2.js index f74dc6b..ac698da 100644 --- a/src/inheritance/problem2.js +++ b/src/inheritance/problem2.js @@ -1,23 +1,29 @@ // Correct all the mistakes in this file class Shape { + constructor(shapeName) { - this.shapName = shapeName; + this.shapeName = shapeName; } + toString() { return this.shapeName + " with area " + - this.area() + " and perimeter " + this.permeter(); + this.area() + " and perimeter " + this.perimeter(); } } -class Square { +class Square extends Shape{ + constructor(size) { - supr("square"); + + super("square"); this.size = size; } + area() { - return this.size * this.siz; + return this.size * this.size; } + perimeter() { return this.size * 4; } diff --git a/src/variable-scoping/problem1.js b/src/variable-scoping/problem1.js index da8f429..a0af8d1 100644 --- a/src/variable-scoping/problem1.js +++ b/src/variable-scoping/problem1.js @@ -3,8 +3,9 @@ // The first time it is called it returns 1 // Every call thereafter returns a number one greater than the last +var x = 0; + function f() { - var x = 0; x = x + 1; return x; } diff --git a/test.txt b/test.txt deleted file mode 100644 index e69de29..0000000