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!

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


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
228,077 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.