From 5dcfc14c2c6fbd0280488e289a2d38f389c5ece4 Mon Sep 17 00:00:00 2001 From: Martin Raquion Date: Tue, 28 May 2019 15:40:41 +0800 Subject: [PATCH 1/3] Solved Problem 1-5 --- practice.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/practice.js b/practice.js index a9e0f69..369f12e 100644 --- a/practice.js +++ b/practice.js @@ -1,4 +1,4 @@ -/* +5/* Once you complete a problem, refresh ./SpecRunner.html in your browser and check to see if the problem's test(s) are passing. Passed tests will be indicated by a green circle. Failed tests will be indicated by a red X. @@ -28,6 +28,9 @@ */ // Code Here +function first(names, cb){ + return cb(names[0]); +} // Do not edit the code below. var names = ['Aodhan', 'Greg', 'Jake', 'Oscar', 'Aodhan', 'Tanner', 'Greg']; @@ -48,6 +51,9 @@ first(names, function(firstName){ */ //Code Here +function last(names, cb){ + return cb(names[names.length-1]); +} // Do not edit the code below. last(names, function(lastName){ @@ -66,6 +72,9 @@ last(names, function(lastName){ */ //Code Here +function multiply(a,b,cb){ + return cb(a*b); +} // Do not edit the code below. multiply(4, 3, function(answer){ @@ -85,6 +94,12 @@ multiply(4, 3, function(answer){ */ //Code Here +function contains(array, name, cb){ + for(let x=0; x<=array.length;x++){ + return (array[x]===name) ? cb(true):cb(false); + } + } + // Do not edit the code below. contains(names, 'Oscar', function(result){ @@ -107,6 +122,11 @@ contains(names, 'Oscar', function(result){ //Code Here +function uniq(arr, cb){ + var newArr= Array.from(new Set(arr)) +cb(newArr); +} + // 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 d9009929ea5ba531b3410a583382232abbbc4764 Mon Sep 17 00:00:00 2001 From: Martin Raquion Date: Tue, 28 May 2019 15:57:00 +0800 Subject: [PATCH 2/3] Solved Problem 6-7 --- practice.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/practice.js b/practice.js index 369f12e..e07fbfd 100644 --- a/practice.js +++ b/practice.js @@ -143,6 +143,12 @@ uniq(names, function(uniqArr){ */ //Code Here +function each(names, cb){ + names.forEach(name =>{ + return cb(name, name.indexOf(name)) + }); +} + // Do not edit the code below. each(names, function(item, indice){ @@ -161,6 +167,14 @@ each(names, function(item, indice){ // Code here +function getUserById(user_obj, id, cb){ + for(let i = 0; i<=user_obj.length;i++){ + if(user_obj[i].id === id){ + return cb(user_obj[i]); + } + } +} + // Do not edit the code below. var users = [ { From 46bde1da9a5a2c84ce908f7de23d8e86fae96e96 Mon Sep 17 00:00:00 2001 From: Martin Raquion Date: Tue, 28 May 2019 15:57:51 +0800 Subject: [PATCH 3/3] modified user.json --- user.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/user.json b/user.json index 4ac80a0..02b0215 100644 --- a/user.json +++ b/user.json @@ -1,4 +1,4 @@ { - "name": "", - "email": "" + "name": "Martin Earl Raquion", + "email": "martin.raquion@boom.camp" }