From 1a93301ba10cdb753360a89cfb6109c16556d56b Mon Sep 17 00:00:00 2001 From: rapraquion Date: Wed, 16 Oct 2019 01:00:03 -0400 Subject: [PATCH 1/5] editted user.json & solved prob #1 --- practice.js | 86 ++++++++++++++++++++++++++--------------------------- user.json | 4 +-- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/practice.js b/practice.js index a9e0f69..088d81f 100644 --- a/practice.js +++ b/practice.js @@ -28,18 +28,18 @@ */ // Code Here - +var first = function(firstName, names) { + names(firstName[0]); +}; // Do not edit the code below. -var names = ['Aodhan', 'Greg', 'Jake', 'Oscar', 'Aodhan', 'Tanner', 'Greg']; +var names = ["Aodhan", "Greg", "Jake", "Oscar", "Aodhan", "Tanner", "Greg"]; -first(names, function(firstName){ - console.log('The first name in names is ' + firstName); +first(names, function(firstName) { + console.log("The first name in names is " + firstName); return firstName; }); // Do not edit the code above. - - ////////// PROBLEM 2 ////////// /* @@ -50,14 +50,12 @@ first(names, function(firstName){ //Code Here // Do not edit the code below. -last(names, function(lastName){ - console.log('The last name in names is ' + lastName); +last(names, function(lastName) { + console.log("The last name in names is " + lastName); return lastName; }); // Do not edit the code above. - - ////////// PROBLEM 3 ////////// /* @@ -68,13 +66,11 @@ last(names, function(lastName){ //Code Here // Do not edit the code below. -multiply(4, 3, function(answer){ - console.log('The answer is ' + answer); //should console.log "The answer is 12" +multiply(4, 3, function(answer) { + console.log("The answer is " + answer); //should console.log "The answer is 12" }); // Do not edit the code above. - - ////////// PROBLEM 4 ////////// /* @@ -87,17 +83,15 @@ multiply(4, 3, function(answer){ //Code Here // Do not edit the code below. -contains(names, 'Oscar', function(result){ - if(result === true){ - console.log('Oscar is in the array'); +contains(names, "Oscar", function(result) { + if (result === true) { + console.log("Oscar is in the array"); } else { - console.log('Oscar is not in the array'); + console.log("Oscar is not in the array"); } }); // Do not edit the code above. - - ////////// PROBLEM 5 ////////// /* @@ -108,13 +102,14 @@ contains(names, 'Oscar', function(result){ //Code Here // Do not edit the code below. -uniq(names, function(uniqArr){ - console.log('The new names array with all the duplicate items removed is ', uniqArr); +uniq(names, function(uniqArr) { + console.log( + "The new names array with all the duplicate items removed is ", + uniqArr + ); }); // Do not edit the code above. - - ////////// PROBLEM 6 ////////// /* @@ -125,13 +120,11 @@ uniq(names, function(uniqArr){ //Code Here // Do not edit the code below. -each(names, function(item, indice){ - console.log('The item in the ' + indice + ' position is ' + item) +each(names, function(item, indice) { + console.log("The item in the " + indice + " position is " + item); }); // Do not edit the code above. - - ////////// PROBLEM 7 ////////// /* @@ -144,26 +137,33 @@ each(names, function(item, indice){ // Do not edit the code below. var users = [ { - id: '12d', - email: 'aodhan@boom.camp', - name: 'Aodhan', - address: '167 East 500 North' + id: "12d", + email: "aodhan@boom.camp", + name: "Aodhan", + address: "167 East 500 North" }, { - id: '15a', - email: 'greg@boom.camp', - name: 'Greg', - address: '135 East 320 North' + id: "15a", + email: "greg@boom.camp", + name: "Greg", + address: "135 East 320 North" }, { - id: '16t', - email: 'Oscar@boom.camp', - name: 'Oscar', - address: '192 East 32 North' - }, + id: "16t", + email: "Oscar@boom.camp", + name: "Oscar", + address: "192 East 32 North" + } ]; -getUserById(users, '16t', function(user){ - console.log('The user with the id 16t has the email of ' + user.email + ' the name of ' + user.name + ' and the address of ' + user.address); +getUserById(users, "16t", function(user) { + console.log( + "The user with the id 16t has the email of " + + user.email + + " the name of " + + user.name + + " and the address of " + + user.address + ); }); // Do not edit the code above. diff --git a/user.json b/user.json index 4ac80a0..f01ef9d 100644 --- a/user.json +++ b/user.json @@ -1,4 +1,4 @@ { - "name": "", - "email": "" + "name": "Raphael Raquion", + "email": "raphael.raquion@boom.camp" } From 07dc0d9b49d0ce519cd212d414849ceff161b3fe Mon Sep 17 00:00:00 2001 From: rapraquion Date: Wed, 16 Oct 2019 01:08:04 -0400 Subject: [PATCH 2/5] solved prob #2 --- practice.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/practice.js b/practice.js index 088d81f..dc68763 100644 --- a/practice.js +++ b/practice.js @@ -48,7 +48,9 @@ first(names, function(firstName) { */ //Code Here - +var last = function(lastName, names) { + names(lastName[lastName.length - 1]); +}; // Do not edit the code below. last(names, function(lastName) { console.log("The last name in names is " + lastName); From 8b0abf5be067bacbc6cbeba21a2fc62572cb14f5 Mon Sep 17 00:00:00 2001 From: rapraquion Date: Wed, 16 Oct 2019 01:24:07 -0400 Subject: [PATCH 3/5] solved prob #3 --- practice.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/practice.js b/practice.js index dc68763..89743f4 100644 --- a/practice.js +++ b/practice.js @@ -66,7 +66,9 @@ last(names, function(lastName) { */ //Code Here - +var multiply = function(x, y, answer) { + answer(x * y); +}; // Do not edit the code below. multiply(4, 3, function(answer) { console.log("The answer is " + answer); //should console.log "The answer is 12" @@ -83,7 +85,7 @@ multiply(4, 3, function(answer) { */ //Code Here - +var contains = function(array, name, result) {}; // Do not edit the code below. contains(names, "Oscar", function(result) { if (result === true) { @@ -102,7 +104,7 @@ contains(names, "Oscar", function(result) { */ //Code Here - +var uniq = function(uniqArr, names) {}; // Do not edit the code below. uniq(names, function(uniqArr) { console.log( @@ -120,7 +122,7 @@ uniq(names, function(uniqArr) { */ //Code Here - +var each = function(names, items, indice) {}; // Do not edit the code below. each(names, function(item, indice) { console.log("The item in the " + indice + " position is " + item); @@ -135,7 +137,7 @@ each(names, function(item, indice) { */ // Code here - +var getUserById = function(users, id, user) {}; // Do not edit the code below. var users = [ { From 974d24911162ed83b56c349b3d3b4dddd7c750d2 Mon Sep 17 00:00:00 2001 From: rapraquion Date: Wed, 16 Oct 2019 03:29:05 -0400 Subject: [PATCH 4/5] solved prob #4-6 --- practice.js | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/practice.js b/practice.js index 89743f4..47f5412 100644 --- a/practice.js +++ b/practice.js @@ -28,9 +28,9 @@ */ // Code Here -var first = function(firstName, names) { +function first(firstName, names) { names(firstName[0]); -}; +} // Do not edit the code below. var names = ["Aodhan", "Greg", "Jake", "Oscar", "Aodhan", "Tanner", "Greg"]; @@ -48,9 +48,9 @@ first(names, function(firstName) { */ //Code Here -var last = function(lastName, names) { +function last(lastName, names) { names(lastName[lastName.length - 1]); -}; +} // Do not edit the code below. last(names, function(lastName) { console.log("The last name in names is " + lastName); @@ -66,9 +66,9 @@ last(names, function(lastName) { */ //Code Here -var multiply = function(x, y, answer) { +function multiply(x, y, answer) { answer(x * y); -}; +} // Do not edit the code below. multiply(4, 3, function(answer) { console.log("The answer is " + answer); //should console.log "The answer is 12" @@ -85,7 +85,15 @@ multiply(4, 3, function(answer) { */ //Code Here -var contains = function(array, name, result) {}; +function contains(names, name, result) { + for (let val of names) { + if (val === name) { + result(true); + } else { + result(false); + } + } +} // Do not edit the code below. contains(names, "Oscar", function(result) { if (result === true) { @@ -104,7 +112,10 @@ contains(names, "Oscar", function(result) { */ //Code Here -var uniq = function(uniqArr, names) {}; +function uniq(names, arr) { + let uniqArr = [...new Set(names)]; + arr(uniqArr); +} // Do not edit the code below. uniq(names, function(uniqArr) { console.log( @@ -122,7 +133,14 @@ uniq(names, function(uniqArr) { */ //Code Here -var each = function(names, items, indice) {}; +function each(names, index) { + // for (let i = 0; i < names.length - 1; i++) { + // index(names[i], i); + // } + for (value of names) { + index(value, names.indexOf(value)); + } +} // Do not edit the code below. each(names, function(item, indice) { console.log("The item in the " + indice + " position is " + item); @@ -137,7 +155,7 @@ each(names, function(item, indice) { */ // Code here -var getUserById = function(users, id, user) {}; +function getUserById(users, id, user) {} // Do not edit the code below. var users = [ { From a8eb224d355c69c6a6a9df8a4c8ea18d3ce82151 Mon Sep 17 00:00:00 2001 From: rapraquion Date: Wed, 16 Oct 2019 03:34:17 -0400 Subject: [PATCH 5/5] solved prob #7 --- practice.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/practice.js b/practice.js index 47f5412..070229d 100644 --- a/practice.js +++ b/practice.js @@ -155,7 +155,12 @@ each(names, function(item, indice) { */ // Code here -function getUserById(users, id, user) {} +function getUserById(users, id, res) { + for (values of users) + if (values.id == id) { + res(values); + } +} // Do not edit the code below. var users = [ {