From 04ef426c991cdb1891b0376616c5573b10991af5 Mon Sep 17 00:00:00 2001 From: Micko Matamorosa Date: Wed, 16 Oct 2019 16:57:29 +0800 Subject: [PATCH 1/2] Done Callbacks --- practice.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- user.json | 4 ++-- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/practice.js b/practice.js index a9e0f69..fbccb80 100644 --- a/practice.js +++ b/practice.js @@ -28,7 +28,9 @@ */ // Code Here - +function first(arr,cb){ + return cb(arr[0]); +} // Do not edit the code below. var names = ['Aodhan', 'Greg', 'Jake', 'Oscar', 'Aodhan', 'Tanner', 'Greg']; @@ -49,6 +51,10 @@ first(names, function(firstName){ //Code Here +function last(arr,cb){ + return cb(arr[arr.length-1]); +} + // Do not edit the code below. last(names, function(lastName){ console.log('The last name in names is ' + lastName); @@ -66,7 +72,9 @@ last(names, function(lastName){ */ //Code Here - +function multiply(x,y,cb){ + return cb(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 +93,15 @@ multiply(4, 3, function(answer){ */ //Code Here - +function contains(arrr,name,cb){ + for(let i=0; i { + indice += 1; + return cb(element,indice) + }); + + // for(let i=0;i Date: Wed, 16 Oct 2019 17:57:47 +0800 Subject: [PATCH 2/2] Done Callbacks --- practice.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice.js b/practice.js index fbccb80..08386fd 100644 --- a/practice.js +++ b/practice.js @@ -180,7 +180,7 @@ each(names, function(item, indice){ // Code here function getUserById(users,id,cb){ for(let i=0; i