diff --git a/practice.js b/practice.js index a9e0f69..070229d 100644 --- a/practice.js +++ b/practice.js @@ -28,18 +28,18 @@ */ // Code Here - +function first(firstName, names) { + names(firstName[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 +48,16 @@ first(names, function(firstName){ */ //Code Here - +function last(lastName, names) { + names(lastName[lastName.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 +66,15 @@ last(names, function(lastName){ */ //Code Here - +function multiply(x, y, answer) { + answer(x * y); +} // 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 +85,25 @@ multiply(4, 3, function(answer){ */ //Code Here - +function contains(names, name, result) { + for (let val of names) { + if (val === name) { + result(true); + } else { + result(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 +112,19 @@ contains(names, 'Oscar', function(result){ */ //Code Here - +function uniq(names, arr) { + let uniqArr = [...new Set(names)]; + arr(uniqArr); +} // 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 +133,20 @@ uniq(names, function(uniqArr){ */ //Code Here - +function each(names, index) { + // for (let i = 0; i < names.length - 1; i++) { + // index(names[i], i); + // } + for (value of names) { + index(value, names.indexOf(value)); + } +} // 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 +155,42 @@ each(names, function(item, indice){ */ // Code here - +function getUserById(users, id, res) { + for (values of users) + if (values.id == id) { + res(values); + } +} // 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..f01ef9d 100644 --- a/user.json +++ b/user.json @@ -1,4 +1,4 @@ { - "name": "", - "email": "" + "name": "Raphael Raquion", + "email": "raphael.raquion@boom.camp" }