diff --git a/practice.js b/practice.js index a9e0f69..a9698e7 100644 --- a/practice.js +++ b/practice.js @@ -28,6 +28,9 @@ */ // Code Here +function first(names, callback){ + return callback(names[0]); +} // Do not edit the code below. var names = ['Aodhan', 'Greg', 'Jake', 'Oscar', 'Aodhan', 'Tanner', 'Greg']; @@ -48,6 +51,10 @@ first(names, function(firstName){ */ //Code Here +function last(names, callback){ + return callback(names[names.length-1]); +} + // Do not edit the code below. last(names, function(lastName){ @@ -66,6 +73,10 @@ last(names, function(lastName){ */ //Code Here +function multiply(n, c, callback){ + return callback(n*c); +} + // Do not edit the code below. multiply(4, 3, function(answer){ @@ -85,6 +96,13 @@ multiply(4, 3, function(answer){ */ //Code Here +function contains(arr, name, callback){ + if(arr.includes(name)){ + return callback(true); + } else { + return callback(false); + } + } // Do not edit the code below. contains(names, 'Oscar', function(result){ @@ -106,6 +124,11 @@ contains(names, 'Oscar', function(result){ */ //Code Here +function uniq(arr, callback){ + const uniqueAges = arr.filter((x, i, a) => a.indexOf(x) == i) + callback(uniqueAges); +} + // Do not edit the code below. uniq(names, function(uniqArr){ @@ -123,6 +146,12 @@ uniq(names, function(uniqArr){ */ //Code Here +function each(names, callback){ + for (let c=0; c < names.length; c++){ + callback(names[c], c); + } +} + // Do not edit the code below. each(names, function(item, indice){ @@ -140,6 +169,13 @@ each(names, function(item, indice){ */ // Code here +function getUserById(users, id, callback){ + for (let c=0; c