diff --git a/practice.js b/practice.js index a9e0f69..029c6ee 100644 --- a/practice.js +++ b/practice.js @@ -28,18 +28,19 @@ */ // Code Here +function first(arr, callback) { + callback(arr[0]); +} // Do not edit the code below. -var names = ['Aodhan', 'Greg', 'Jake', 'Oscar', 'Aodhan', 'Tanner', 'Greg']; +var names = ["Aodhan", "Greg", "Jake", "Oscar", "Aodhan", "Tanner", "Greg"]; -first(names, function(firstName){ - console.log('The first name in names is ' + firstName); +first(names, function(firstName) { + console.log("The first name in names is " + firstName); return firstName; }); // Do not edit the code above. - - ////////// PROBLEM 2 ////////// /* @@ -48,16 +49,17 @@ 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){ - console.log('The last name in names is ' + lastName); +last(names, function(lastName) { + console.log("The last name in names is " + lastName); return lastName; }); // Do not edit the code above. - - ////////// PROBLEM 3 ////////// /* @@ -66,15 +68,16 @@ last(names, function(lastName){ */ //Code Here +function multiply(num_one, num_two, callback) { + callback(num_one * num_two); +} // Do not edit the code below. -multiply(4, 3, function(answer){ - console.log('The answer is ' + answer); //should console.log "The answer is 12" +multiply(4, 3, function(answer) { + console.log("The answer is " + answer); //should console.log "The answer is 12" }); // Do not edit the code above. - - ////////// PROBLEM 4 ////////// /* @@ -85,19 +88,25 @@ multiply(4, 3, function(answer){ */ //Code Here +function contains(arr, name, callback) { + for (i in arr) { + if (arr[i] == name) { + callback(true); + } + } + callback(false); +} // Do not edit the code below. -contains(names, 'Oscar', function(result){ - if(result === true){ - console.log('Oscar is in the array'); +contains(names, "Oscar", function(result) { + if (result === true) { + console.log("Oscar is in the array"); } else { - console.log('Oscar is not in the array'); + console.log("Oscar is not in the array"); } }); // Do not edit the code above. - - ////////// PROBLEM 5 ////////// /* @@ -106,15 +115,20 @@ contains(names, 'Oscar', function(result){ */ //Code Here +function uniq(arr, callback) { + let unique_array = Array.from(new Set(arr)); + callback(unique_array); +} // Do not edit the code below. -uniq(names, function(uniqArr){ - console.log('The new names array with all the duplicate items removed is ', uniqArr); +uniq(names, function(uniqArr) { + console.log( + "The new names array with all the duplicate items removed is ", + uniqArr + ); }); // Do not edit the code above. - - ////////// PROBLEM 6 ////////// /* @@ -123,15 +137,18 @@ uniq(names, function(uniqArr){ */ //Code Here +function each(arr, callback) { + for (i in arr) { + callback(arr[i], i - 1); + } +} // Do not edit the code below. -each(names, function(item, indice){ - console.log('The item in the ' + indice + ' position is ' + item) +each(names, function(item, indice) { + console.log("The item in the " + indice + " position is " + item); }); // Do not edit the code above. - - ////////// PROBLEM 7 ////////// /* @@ -140,30 +157,44 @@ each(names, function(item, indice){ */ // Code here +function getUserById(arr, id, callback) { + for (i in arr) { + if (arr[i].id == id) { + callback(arr[i]); + } + } +} // Do not edit the code below. var users = [ { - id: '12d', - email: 'aodhan@boom.camp', - name: 'Aodhan', - address: '167 East 500 North' + id: "12d", + email: "aodhan@boom.camp", + name: "Aodhan", + address: "167 East 500 North" }, { - id: '15a', - email: 'greg@boom.camp', - name: 'Greg', - address: '135 East 320 North' + id: "15a", + email: "greg@boom.camp", + name: "Greg", + address: "135 East 320 North" }, { - id: '16t', - email: 'Oscar@boom.camp', - name: 'Oscar', - address: '192 East 32 North' - }, + id: "16t", + email: "Oscar@boom.camp", + name: "Oscar", + address: "192 East 32 North" + } ]; -getUserById(users, '16t', function(user){ - console.log('The user with the id 16t has the email of ' + user.email + ' the name of ' + user.name + ' and the address of ' + user.address); +getUserById(users, "16t", function(user) { + console.log( + "The user with the id 16t has the email of " + + user.email + + " the name of " + + user.name + + " and the address of " + + user.address + ); }); // Do not edit the code above. diff --git a/user.json b/user.json index 4ac80a0..ab76377 100644 --- a/user.json +++ b/user.json @@ -1,4 +1,4 @@ { - "name": "", - "email": "" + "name": "Noe Philip Gabriel M. Restum ", + "email": "noe.restum@boom.camp" }