From 6234990761b87b3d23953f61708e91e30bcaacfa Mon Sep 17 00:00:00 2001 From: snowcoding Date: Mon, 21 May 2018 13:38:27 -0700 Subject: [PATCH 1/4] Finished arrays and objects --- assignments/arrays.js | 37 ++++++++++++++++++++++++------ assignments/objects.js | 51 +++++++++++++++++++++++++++++++++++------- 2 files changed, 73 insertions(+), 15 deletions(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index c007f3e99..e5caf08f6 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -63,34 +63,57 @@ let inventory = [{"id":1,"car_make":"Lincoln","car_model":"Navigator","car_year" // ==== Challenge 1 ==== // The dealer can't recall the information for a car with an id of 33 on his lot. Help the dealer find out which car has an id of 33 by logging the car's year, make, and model in the console log provided to you below: -console.log(`Car 33 is a *car year goes here* *car make goes here* *car model goes here*` ); + +for (i=0;i Date: Mon, 21 May 2018 14:54:17 -0700 Subject: [PATCH 2/4] Finished callbacks --- assignments/callbacks.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/assignments/callbacks.js b/assignments/callbacks.js index a551f853b..131df6eb4 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -2,27 +2,33 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; function firstItem(arr, cb) { // firstItem passes the first item of the given array to the callback function. + cb(arr[0]); } function getLength(arr, cb) { // getLength passes the length of the array into the callback. + cb(arr.length); } function last(arr, cb) { // last passes the last item of the array into the callback. + cb(arr[arr.length-1]); } function sumNums(x, y, cb) { // sumNums adds two numbers (x, y) and passes the result to the callback. + cb(x+y); } function multiplyNums(x, y, cb) { // multiplyNums multiplies two numbers and passes the result to the callback. + cb(x*y); } function contains(item, list, cb) { // contains checks if an item is present inside of the given array/list. // Pass true to the callback if it is, otherwise pass false. + cb((list.indexOf(item) === -1) ? false : true); } /* STRETCH PROBLEM */ @@ -31,4 +37,10 @@ function removeDuplicates(array, cb) { // removeDuplicates removes all duplicate values from the given array. // Pass the duplicate free array to the callback function. // Do not mutate the original array. + let rd = array.filter(el => array.indexOf(el) == array.lastIndexOf(el)); + cb(rd); +} + +function cb(x){ + console.log(x); } From e7b886e1682f4e1a5768db8bdaf9fb8bf7578c8f Mon Sep 17 00:00:00 2001 From: snowcoding Date: Mon, 21 May 2018 20:56:35 -0700 Subject: [PATCH 3/4] added Quokka --- assignments/objects.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/assignments/objects.js b/assignments/objects.js index 042bafe3e..d7ff64ad6 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -18,10 +18,10 @@ let example = { } // Write your intern objects here: -function Intern(id, email, first, gender){ +function Intern(id, email, name, gender){ this.id = id; this.email = email; - this.first = first; + this.name = name; this.gender = gender; } @@ -56,7 +56,7 @@ kennan.speak = function(){ console.log(kennan.speak()); // Antonietta loves math, give her the ability to multiply two numbers together and return the product. Use the console.log provided as a hint. -antonietta.multiplyNum = function(a,b){ +antonietta.multiplyNums = function(a,b){ return a*b; } console.log(antonietta.multiplyNums(3,4)); @@ -74,10 +74,10 @@ let parent = { name: 'Susan', age: 70, child: { - name: George, + name: 'George', age:50, child:{ - name:Sam, + name:"Sam", age:30, speak: function(){return "My Name is " + this.name;} }, @@ -89,11 +89,15 @@ let parent = { // Log the parent object's name console.log(parent.name); // Log the child's age +console.log(parent.child.name); // Log the name and age of the grandchild +console.log(parent.child.child.name); +console.log(parent.child.child.age); // Have the parent speak - +console.log(parent.speak()); // Have the child speak - +console.log(parent.child.speak()); // Have the grandchild speak +console.log(parent.child.child.speak()); \ No newline at end of file From 5490e28ee2966c4055d135963566aaf6347d87b6 Mon Sep 17 00:00:00 2001 From: snowcoding Date: Tue, 22 May 2018 17:23:07 -0700 Subject: [PATCH 4/4] Modifed callbacks to take into account the calling of the function! --- assignments/callbacks.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/assignments/callbacks.js b/assignments/callbacks.js index 131df6eb4..19117d57b 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -5,31 +5,44 @@ function firstItem(arr, cb) { cb(arr[0]); } +firstItem(items, item => {console.log(item)}) + + function getLength(arr, cb) { // getLength passes the length of the array into the callback. cb(arr.length); } +getLength(items, length => {console.log(length)}) + function last(arr, cb) { // last passes the last item of the array into the callback. cb(arr[arr.length-1]); } +last(items, length => {console.log(length)}) + function sumNums(x, y, cb) { // sumNums adds two numbers (x, y) and passes the result to the callback. cb(x+y); } +sumNums(2,4,sum => {console.log(sum)}) + + function multiplyNums(x, y, cb) { // multiplyNums multiplies two numbers and passes the result to the callback. cb(x*y); } +multiplyNums(2,4,m => {console.log(m)}) + function contains(item, list, cb) { // contains checks if an item is present inside of the given array/list. // Pass true to the callback if it is, otherwise pass false. cb((list.indexOf(item) === -1) ? false : true); } +contains('Pencil',items, c => {console.log(c)}) /* STRETCH PROBLEM */ @@ -37,10 +50,11 @@ function removeDuplicates(array, cb) { // removeDuplicates removes all duplicate values from the given array. // Pass the duplicate free array to the callback function. // Do not mutate the original array. - let rd = array.filter(el => array.indexOf(el) == array.lastIndexOf(el)); + let rd = array.filter(function(item, pos,arr) { + return arr.indexOf(item) == pos; + }) + cb(rd); } -function cb(x){ - console.log(x); -} +removeDuplicates([1,2,1,2,3,4],c => {console.log(c)})