Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Doing some Javascript problems and this is the only one I can't seem to figure out. Any help would be amazing. Thanks.

function lastLetterSort(stringArray) { function byLastLetter(a, b) { //TODO: Sort the strings in alphabetical // order using their last letter // Read this about how the sort function works: // this byLastLetter function is a "compare function" // And check out the "comparing strings" section here: } stringArray.sort(byLastLetter); }

function sumArray(numberArray) { var sum = 0; // TODO: implement me using forEach return sum; }

function sumSort(arrayOfArrays) { arrayOfArrays.sort(function(item) { // TODO: implement me using sumArray // order the arrays based on the sum of the numbers // inside each array }); }

1 Answer

Steven Parker
Steven Parker
215,939 Points

It looks like you have several problems here. Which one are you stuck on?

Here's one of them, just in case (or to get you started):

function sumArray(numberArray) {
  var sum = 0;
    sum += n;
  return sum;

:information_source: I should point out that .forEach() is less efficient than an ordinary for loop and indexing.

I didn't notice that. sorry man. I was stuck on sumArray but that helps. Thank you.