From c1c22a055c5bf125486fd37de8db5bc08845210a Mon Sep 17 00:00:00 2001 From: marvin banton Date: Tue, 28 May 2019 14:17:19 +0800 Subject: [PATCH 1/8] Added user.json --- user.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/user.json b/user.json index 4ac80a0..ed7c1c0 100644 --- a/user.json +++ b/user.json @@ -1,4 +1,4 @@ { - "name": "", - "email": "" + "name": "Marvin Banton", + "email": "marvin.banton@boom.camp" } From 7cc880fe60cfaad1cc5cd3094558cebd3a5ad3ec Mon Sep 17 00:00:00 2001 From: marvin banton Date: Tue, 28 May 2019 14:18:01 +0800 Subject: [PATCH 2/8] Done Problem 1 --- practice.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/practice.js b/practice.js index a9e0f69..fa9878e 100644 --- a/practice.js +++ b/practice.js @@ -28,7 +28,9 @@ */ // Code Here - +function first (arr, cb) { + cb(arr[0]); +} // Do not edit the code below. var names = ['Aodhan', 'Greg', 'Jake', 'Oscar', 'Aodhan', 'Tanner', 'Greg']; From d3e2ef706384b8655dee7dbf5a5fb5cf5f99f1cf Mon Sep 17 00:00:00 2001 From: marvin banton Date: Tue, 28 May 2019 14:18:50 +0800 Subject: [PATCH 3/8] Done Problem 2 --- practice.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/practice.js b/practice.js index fa9878e..7d688f0 100644 --- a/practice.js +++ b/practice.js @@ -50,7 +50,9 @@ first(names, function(firstName){ */ //Code Here - +function last (arr, cb) { + cb(arr[arr.length -1]); +} // Do not edit the code below. last(names, function(lastName){ console.log('The last name in names is ' + lastName); From 94a95a2d0abfb8c8e8a4a24b7a528a387474f9c5 Mon Sep 17 00:00:00 2001 From: marvin banton Date: Tue, 28 May 2019 14:19:13 +0800 Subject: [PATCH 4/8] Done Problem 3 --- practice.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/practice.js b/practice.js index 7d688f0..104b585 100644 --- a/practice.js +++ b/practice.js @@ -70,7 +70,9 @@ last(names, function(lastName){ */ //Code Here - +function multiply (num1, num2, cb) { + cb(num1 * num2); +} // Do not edit the code below. multiply(4, 3, function(answer){ console.log('The answer is ' + answer); //should console.log "The answer is 12" From 60221d19ae7272165128ccebbc0410404952b09f Mon Sep 17 00:00:00 2001 From: marvin banton Date: Tue, 28 May 2019 14:19:35 +0800 Subject: [PATCH 5/8] Done Problem 4 --- practice.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/practice.js b/practice.js index 104b585..401744f 100644 --- a/practice.js +++ b/practice.js @@ -91,7 +91,9 @@ multiply(4, 3, function(answer){ */ //Code Here - +function contains (arr, name, cb) { + arr.map(val => val == name ? cb(true): cb(false)); +} // Do not edit the code below. contains(names, 'Oscar', function(result){ if(result === true){ From 95531f8860b036d9e78263feeb765b7cbc217e06 Mon Sep 17 00:00:00 2001 From: marvin banton Date: Tue, 28 May 2019 14:20:02 +0800 Subject: [PATCH 6/8] Done Problem 5 --- practice.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/practice.js b/practice.js index 401744f..3ae1c24 100644 --- a/practice.js +++ b/practice.js @@ -114,7 +114,9 @@ contains(names, 'Oscar', function(result){ */ //Code Here - +function uniq (arr, cb) { + cb([...new Set(arr)]); +} // Do not edit the code below. uniq(names, function(uniqArr){ console.log('The new names array with all the duplicate items removed is ', uniqArr); From 3168bb1456b8c48322b6664191872b4b57be1c89 Mon Sep 17 00:00:00 2001 From: marvin banton Date: Tue, 28 May 2019 14:23:38 +0800 Subject: [PATCH 7/8] Done Problem 6 --- practice.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/practice.js b/practice.js index 3ae1c24..a32974f 100644 --- a/practice.js +++ b/practice.js @@ -133,7 +133,11 @@ uniq(names, function(uniqArr){ */ //Code Here - +function each (arr, cb) { + for (i of arr) { + cb (i, arr.indexOf(i)); + } +} // Do not edit the code below. each(names, function(item, indice){ console.log('The item in the ' + indice + ' position is ' + item) @@ -141,7 +145,6 @@ each(names, function(item, indice){ // Do not edit the code above. - ////////// PROBLEM 7 ////////// /* @@ -150,7 +153,13 @@ each(names, function(item, indice){ */ // Code here - +function getUserById (arr, id, cb) { + for(i of arr) { + if(i.id == id) { + cb(i); + } + } +} // Do not edit the code below. var users = [ { From 3a2bee7296d1ed7a9eb84a4c4db374b85d491498 Mon Sep 17 00:00:00 2001 From: marvin banton Date: Tue, 28 May 2019 14:23:51 +0800 Subject: [PATCH 8/8] Done Problem 7 --- practice.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice.js b/practice.js index a32974f..6ea68cc 100644 --- a/practice.js +++ b/practice.js @@ -159,7 +159,7 @@ function getUserById (arr, id, cb) { cb(i); } } -} +} // Do not edit the code below. var users = [ {