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
46 changes: 44 additions & 2 deletions practice.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*

/*
Once you complete a problem, refresh ./SpecRunner.html in your browser and check to see if the problem's test(s) are passing.
Passed tests will be indicated by a green circle.
Failed tests will be indicated by a red X.
Expand Down Expand Up @@ -29,6 +30,10 @@

// Code Here

var first = function(array, callback){
callback(array[0]);
}

// Do not edit the code below.
var names = ['Aodhan', 'Greg', 'Jake', 'Oscar', 'Aodhan', 'Tanner', 'Greg'];

Expand All @@ -47,6 +52,11 @@ first(names, function(firstName){
Then invoke the callback, passing in the last element in the array as the argument.
*/


var last = function(array, callback){
callback(array[array.length - 1]);
}

//Code Here

// Do not edit the code below.
Expand All @@ -67,6 +77,10 @@ last(names, function(lastName){

//Code Here

var multiply = function(num1, num2, callback){
callback(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,6 +99,9 @@ multiply(4, 3, function(answer){
*/

//Code Here
var contains = function(names, name, callback){
callback(names.indexOf(name)>-1?true:false);
}

// Do not edit the code below.
contains(names, 'Oscar', function(result){
Expand All @@ -107,6 +124,19 @@ contains(names, 'Oscar', function(result){

//Code Here

var uniq = function(names, callback){
let resAr = [], i = 0;

names.map(name=>{

names.indexOf(name,(i+1)) === -1 ? resAr.push(name): null
i++;

});

callback(resAr);
}

// 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,10 +153,15 @@ uniq(names, function(uniqArr){
*/

//Code Here
var each = function(names, callback){
for (name of names){
callback(name, names.indexOf(name));
}
}

// Do not edit the code below.
each(names, function(item, indice){
console.log('The item in the ' + indice + ' position is ' + item)
console.log('The item in the ' + indice + ' position is ' + item);
});
// Do not edit the code above.

Expand All @@ -140,6 +175,13 @@ each(names, function(item, indice){
*/

// Code here
var getUserById = function(users, id, callback){
users.map(user=>{
if(user.id===id){
callback(user);
}
});
}

// 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": "Jeffrey Molleno",
"email": "jeffrey.molleno@boom.camp"
}