diff --git a/practice.js b/practice.js index a9e0f69..6ea68cc 100644 --- a/practice.js +++ b/practice.js @@ -28,7 +28,9 @@ */ // Code Here - +function first (arr, cb) { + cb(arr[0]); +} // Do not edit the code below. var names = ['Aodhan', 'Greg', 'Jake', 'Oscar', 'Aodhan', 'Tanner', 'Greg']; @@ -48,7 +50,9 @@ first(names, function(firstName){ */ //Code Here - +function last (arr, cb) { + 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 +70,9 @@ last(names, function(lastName){ */ //Code Here - +function multiply (num1, num2, cb) { + cb(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" @@ -85,7 +91,9 @@ multiply(4, 3, function(answer){ */ //Code Here - +function contains (arr, name, cb) { + arr.map(val => val == name ? cb(true): cb(false)); +} // Do not edit the code below. contains(names, 'Oscar', function(result){ if(result === true){ @@ -106,7 +114,9 @@ contains(names, 'Oscar', function(result){ */ //Code Here - +function uniq (arr, cb) { + cb([...new Set(arr)]); +} // Do not edit the code below. uniq(names, function(uniqArr){ console.log('The new names array with all the duplicate items removed is ', uniqArr); @@ -123,7 +133,11 @@ uniq(names, function(uniqArr){ */ //Code Here - +function each (arr, cb) { + for (i of arr) { + cb (i, arr.indexOf(i)); + } +} // Do not edit the code below. each(names, function(item, indice){ console.log('The item in the ' + indice + ' position is ' + item) @@ -131,7 +145,6 @@ each(names, function(item, indice){ // Do not edit the code above. - ////////// PROBLEM 7 ////////// /* @@ -140,7 +153,13 @@ each(names, function(item, indice){ */ // Code here - +function getUserById (arr, id, cb) { + for(i of arr) { + if(i.id == id) { + cb(i); + } + } +} // Do not edit the code below. var users = [ { diff --git a/user.json b/user.json index 4ac80a0..ed7c1c0 100644 --- a/user.json +++ b/user.json @@ -1,4 +1,4 @@ { - "name": "", - "email": "" + "name": "Marvin Banton", + "email": "marvin.banton@boom.camp" }