ga-wdi-boston / js-boggle-challenge

Other
0 stars 158 forks source link

Would a more verbose solution in addition to the current solutions add value to beginner developers? #71

Open MicFin opened 7 years ago

MicFin commented 7 years ago

The current solution uses array methods and functions ins and outs which are not covered yet when Boggle is presented. I recognize it is a challenge so it should push their boundaries and the solution is very elegant. I wonder if also having a more verbose solution would be a nice addition to the solution branch. I've also added comments to the solution, I find comments very useful especially for new developers. Comments can often answer questions that they might otherwise ask a consultant.


// function name: boggle4x4 
// parameters: an array as the tray parameter and an array as the coordPairs parameter
// returns: a string
const boggle4x4 = function(tray, coordPairs) {

   // define a variable as an empty array
   let letters = [];

   // define a variable as a number 
   let trayPosition = 0;

   // loop through the coordPairs so we can access each element in the array
   for (let i = 0; i < coordPairs.length; i++) {

        // access the values in the coordPair array to get the tray position 
        trayPosition = coordPairs[i][0] * 4 + coordPairs[i][1];

        // add the letter in the tray position to the letters array
        letters[i] = tray[trayPosition];
    }

   // return the letters array as a combined string 
   return letters.join("");
}
gaand commented 7 years ago

I'm not opposed. I'd want to keep the short solutions as well. Maybe a refactoring of brute force solutions to DRY solutions?

danman01 commented 7 years ago

I like the idea of a more verbose and commented solution. The refactored solution is great as an exercise in understanding that piece of code. I like the idea of having both. Thinking of code wars, looking through the solutions and comments on the solutions is a great way to learn new techniques and thought processes. I wonder if having a way for students to submit solutions to challenges and have others comment on them, maybe in something like public gists, would be useful / appropriate.