diff --git a/practice.js b/practice.js index a9e0f69..31ce541 100644 --- a/practice.js +++ b/practice.js @@ -29,6 +29,10 @@ // Code Here +function first(array, callback) { + callback(array[0]) + } + // Do not edit the code below. var names = ['Aodhan', 'Greg', 'Jake', 'Oscar', 'Aodhan', 'Tanner', 'Greg']; @@ -47,8 +51,10 @@ first(names, function(firstName){ Then invoke the callback, passing in the last element in the array as the argument. */ -//Code Here - +function last(array, callback) { + callback(array[array.length - 1]) + } + // Do not edit the code below. last(names, function(lastName){ console.log('The last name in names is ' + lastName); @@ -67,6 +73,10 @@ last(names, function(lastName){ //Code Here +function multiply (num1, num2, callback) { + return callback (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" @@ -86,6 +96,15 @@ multiply(4, 3, function(answer){ //Code Here +function contains(array, names, callback) { + if (array.includes(names)) { + callback(true); + } + else { + callback(false); + } + } + // Do not edit the code below. contains(names, 'Oscar', function(result){ if(result === true){ @@ -107,6 +126,12 @@ contains(names, 'Oscar', function(result){ //Code Here +function uniq (array, callback) { + var duplicate = + array.filter(function(cur, ind, array){return array.indexOf(cur) == ind}); + callback (duplicate); + } + // Do not edit the code below. uniq(names, function(uniqArr){ console.log('The new names array with all the duplicate items removed is ', uniqArr); @@ -124,6 +149,12 @@ uniq(names, function(uniqArr){ //Code Here +function each (array, callback) { + for (let i = 0; i < array.length; i++) { + callback(array[i], i); + } +} + // Do not edit the code below. each(names, function(item, indice){ console.log('The item in the ' + indice + ' position is ' + item) @@ -141,6 +172,14 @@ each(names, function(item, indice){ // Code here +function getUserById (array, id, callback) { + for (var i = 0; i < array.length; i++) { + if (id == array[i]) { + } + return callback(array[i]); + } +} + // Do not edit the code below. var users = [ { diff --git a/user.json b/user.json index 4ac80a0..2a76775 100644 --- a/user.json +++ b/user.json @@ -1,4 +1,4 @@ { - "name": "", - "email": "" -} + "name": "Robby Ann Eslava", + "email": "robbyann.eslava@boom.camp" +} \ No newline at end of file