Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

chris salvi
chris salvi
7,584 Points

future lessons on closures and higher order functions in javascript?

I think both of these topics would really benefit people learning JS and although books like elegant js cover them well, I still like the reinforcement. Would be great to see whoever is heading JS lessons to add this to the pipeline.

chris salvi
chris salvi
7,584 Points

especially higher order functions. I got hammered in my interview to hacker school despite being knowledgeable in many other areas of js, and thus wasnt accepted :( They must be pretty crucial to modern JS libraries if they insist on testing people on these skills before accepting them

2 Answers

Dave McFarland
STAFF
Dave McFarland
Treehouse Teacher

HI chris salvi

Great idea. What questions did they ask you? Do you remember?

chris salvi
chris salvi
7,584 Points

yes I actually do remember, but I am at work right now so I will have to wait until later to post them. Basically I knew how to do half of them without much issue, but struggled on the other half because I felt sideswiped on what I didn't think was such a critical aspect of javascript. Apparently Im wrong.

Ill post them later, and hope to maybe hear some cool lessons coming down the pipeline

Dave McFarland
Dave McFarland
Treehouse Teacher

Thanks chris salvi Looking forward to seeing what these questions are and how we at Treehouse can better prepare you.

chris salvi
chris salvi
7,584 Points

1A. create each

(each is a function that takes two inputs, an array and a callback function. Each performs the callback function on each item in the array.

1B Create each with the same conditions as part A, but now each can also take an object. (struggled here)

2. filter

(filter takes two inputs, an array and a callback function that returns either true or false. It should iterate through each item in the array and return all items when passed into the callback return true. For example:)

function filter(array, callback){
    var newResults = [];
    for(var i=0; i<array.length; i++){
        if(callback(array[i]){
newResults.push(array[i]);
    }    
}
return newResults;
 }
}


var each = function(obj, callback){
    //if is array
    if(Array.isArray(obj)){
        for(var i = 0; i < obj.length; i++){
    callback(obj[i]);
}
}
    //if is object
    else if(typeof obj === object){
    for( var key in obj){
callback(obj[key]);    
}
}
}


function filter(obj, callback){
    var emptyArray=[];
    each(obj, callback)

}
chris salvi
chris salvi
7,584 Points

the code was the answer to one of the questions I missed. I forgot how they worded it exactly but it was a variant of the filter function in 2A that I got correct. Alas I will try to apply again in December and study elegant js more intensely, though it'd be great to have some courses on here before then ;)

Also I sincerely hope the assassins at the hacker school dont consider this unethical for me posting this here. I figured it was open game since they A: rejected me B: made me do my live coding in a google document instead of a text editor.

Dave McFarland
Dave McFarland
Treehouse Teacher

Thanks for the feedback chris salvi This does sound like something we should cover. I'll bring it up with the front end teaching team.

chris salvi
chris salvi
7,584 Points

cool, and I know they use elegant js as a resource to vet their students, although personally I think they should hop on the treehouse bandwagon :)