Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions practice.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
Then invoke the callback function, passing in the first element in the array as it's argument.
*/

// Code Here
function first(array, callback){
callback(array[0]);
}


// Do not edit the code below.
var names = ['Aodhan', 'Greg', 'Jake', 'Oscar', 'Aodhan', 'Tanner', 'Greg'];
Expand All @@ -47,7 +50,9 @@ 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){
Expand All @@ -65,7 +70,9 @@ last(names, function(lastName){
Invoke the callback, passing in the product of the two numbers multiplied as the argument.
*/

//Code Here
function multiply(num1, num2, callback){
callback(num1*num2)
}

// Do not edit the code below.
multiply(4, 3, function(answer){
Expand All @@ -84,7 +91,10 @@ multiply(4, 3, function(answer){
If the name does not exist, invoke the callback with false as the argument.
*/

//Code Here
function contains(array, name, callback){
if (array.includes(name)) callback(true)
else callback(false)
}

// Do not edit the code below.
contains(names, 'Oscar', function(result){
Expand All @@ -105,7 +115,16 @@ contains(names, 'Oscar', function(result){
Remove any duplicate values from the array, and invoke the callback with the modified array as an argument.
*/

//Code Here
function uniq(array, callback){

var uniqueArray = [];
for(i=0; i < array.length; i++){
if(uniqueArray.indexOf(array[i]) === -1) {
uniqueArray.push(array[i]);
}
}
callback(uniqueArray);
}

// Do not edit the code below.
uniq(names, function(uniqArr){
Expand All @@ -122,7 +141,11 @@ uniq(names, function(uniqArr){
For each name in the array, invoke the callback and pass in the name and the name's index as arguments.
*/

//Code Here
function each(array, callback){
for (val of array){
callback(val, array.indexOf(val))
}
}

// Do not edit the code below.
each(names, function(item, indice){
Expand All @@ -139,7 +162,14 @@ each(names, function(item, indice){
When the correct user object is found, invoke the callback with the user object as an argument.
*/

// Code here
function getUserById(users, id, callback){
for (val in users) {
if (users[val].id === id) {
callback(users[val]);
}
}

}

// Do not edit the code below.
var users = [
Expand Down
4 changes: 2 additions & 2 deletions user.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "",
"email": ""
"name": "Lyza Mae B. Mirabete",
"email": "lyza.mirabete@boom.camp"
}