From 6aa248f0faaba30112777fff168219f1ebedf016 Mon Sep 17 00:00:00 2001 From: jaakofalltrade Date: Tue, 28 May 2019 14:26:27 +0800 Subject: [PATCH 1/4] [+] First problem done! --- practice.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/practice.js b/practice.js index a9e0f69..7e4096a 100644 --- a/practice.js +++ b/practice.js @@ -28,6 +28,10 @@ */ // Code Here +function first(arr, callback) { + callback(arr[0]); +} + // Do not edit the code below. var names = ['Aodhan', 'Greg', 'Jake', 'Oscar', 'Aodhan', 'Tanner', 'Greg']; From b79b5ce69ecb7282a7a05a2b0d58b0647dd4dfac Mon Sep 17 00:00:00 2001 From: jaakofalltrade Date: Tue, 28 May 2019 14:28:53 +0800 Subject: [PATCH 2/4] [+] Second and Third Problem completed --- practice.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/practice.js b/practice.js index 7e4096a..1f8372f 100644 --- a/practice.js +++ b/practice.js @@ -52,6 +52,9 @@ first(names, function(firstName){ */ //Code Here +function last(arr,callback) { + callback(arr[arr.length-1]); +} // Do not edit the code below. last(names, function(lastName){ @@ -70,6 +73,9 @@ last(names, function(lastName){ */ //Code Here +function multiply(x, y, callback) { + callback(x*y); +} // Do not edit the code below. multiply(4, 3, function(answer){ From 05871c82ec6aeefc6d09eefb3e9b47d787dc4b74 Mon Sep 17 00:00:00 2001 From: jaakofalltrade Date: Tue, 28 May 2019 15:11:14 +0800 Subject: [PATCH 3/4] [+] All the Problems are completed M'lord --- practice.js | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/practice.js b/practice.js index 1f8372f..396337d 100644 --- a/practice.js +++ b/practice.js @@ -96,6 +96,18 @@ multiply(4, 3, function(answer){ //Code Here +function contains(arr, name, callback) { + let isBool; + for(let x of arr) { + if(x == name) { + callback(true); + } else { + isBool = false; + } + } + callback(isBool); +} + // Do not edit the code below. contains(names, 'Oscar', function(result){ if(result === true){ @@ -112,10 +124,23 @@ contains(names, 'Oscar', function(result){ /* Write a function called uniq that takes in an array and a callback function. - Remove any duplicate values from the array, and invoke the callback with the modified array as an argument. + Remove any duplicate values from the array, and invoke the callback with the modified array as an + argument. */ //Code Here +function uniq(arr, callback) { + for(let x in arr) { + for(let y in arr) { + if(y !== x) { + if(arr[x] == arr[y]) { + arr.splice(y,1); + } + } + } + } + callback(arr); +} // Do not edit the code below. uniq(names, function(uniqArr){ @@ -133,7 +158,11 @@ uniq(names, function(uniqArr){ */ //Code Here - +function each(arrName, callback) { + for(let x in arrName) { + callback(arrName[x], parseInt(x)); + } +} // Do not edit the code below. each(names, function(item, indice){ console.log('The item in the ' + indice + ' position is ' + item) @@ -145,12 +174,19 @@ each(names, function(item, indice){ ////////// PROBLEM 7 ////////// /* - Write a function called getUserById that takes in three parameters: an array of objects (users), an id and a callback, and searches for the user with a matching id. + Write a function called getUserById that takes in three parameters: an array of objects (users), + an id and a callback, and searches for the user with a matching id. When the correct user object is found, invoke the callback with the user object as an argument. */ // Code here - +function getUserById(arrUser, id, callback) { + for(let x of arrUser) { + if(x.id === id) { + callback(x); + } + } +} // Do not edit the code below. var users = [ { From 63d4382bc6139b2f0842aebccbfaa8090e48fcae Mon Sep 17 00:00:00 2001 From: jaakofalltrade Date: Tue, 28 May 2019 15:15:37 +0800 Subject: [PATCH 4/4] [!] Added my info in the user.json file --- user.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/user.json b/user.json index 4ac80a0..77ca022 100644 --- a/user.json +++ b/user.json @@ -1,4 +1,4 @@ { - "name": "", - "email": "" + "name": "Jaako Andes", + "email": "jaako.andes@boom.camp" }