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
35 changes: 27 additions & 8 deletions practice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand All @@ -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);
Expand All @@ -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"
Expand All @@ -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){
Expand All @@ -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);
Expand All @@ -123,15 +133,18 @@ 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)
});
// Do not edit the code above.



////////// PROBLEM 7 //////////

/*
Expand All @@ -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 = [
{
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": "Marvin Banton",
"email": "marvin.banton@boom.camp"
}