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
52 changes: 48 additions & 4 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){
return cb(arr[0]);
}
// Do not edit the code below.
var names = ['Aodhan', 'Greg', 'Jake', 'Oscar', 'Aodhan', 'Tanner', 'Greg'];

Expand All @@ -49,6 +51,10 @@ first(names, function(firstName){

//Code Here

function last(arr,cb){
return 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 +72,9 @@ last(names, function(lastName){
*/

//Code Here

function multiply(x,y,cb){
return cb(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"
Expand All @@ -85,7 +93,15 @@ multiply(4, 3, function(answer){
*/

//Code Here

function contains(arrr,name,cb){
for(let i=0; i<arrr.length; i++){
if(arrr[i] === name){
return cb(true);
}else{
return cb(false);
}
}
}
// Do not edit the code below.
contains(names, 'Oscar', function(result){
if(result === true){
Expand All @@ -106,6 +122,17 @@ contains(names, 'Oscar', function(result){
*/

//Code Here
function uniq(ar,cb){
var obj = {};
var ret_arr = [];
for (var i = 0; i < ar.length; i++) {
obj[ar[i]] = true;
}
for (var key in obj) {
ret_arr.push(key);
}
return cb(ret_arr);
}

// Do not edit the code below.
uniq(names, function(uniqArr){
Expand All @@ -123,6 +150,17 @@ uniq(names, function(uniqArr){
*/

//Code Here
function each(names,cb){
indice = 0;
names.forEach(element => {
indice += 1;
return cb(element,indice)
});

// for(let i=0;i<names.length;i++){
// return cb(names[i], i, names);
// }
}

// Do not edit the code below.
each(names, function(item, indice){
Expand All @@ -140,7 +178,13 @@ each(names, function(item, indice){
*/

// Code here

function getUserById(users,id,cb){
for(let i=0; i<users.length;i++){
if(id != ' '){
return cb(users[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": "Christian Ray Frecia",
"email": "christian.frecia@boom.camp"
}