Challenge 11 Help


#1

I’ve done challenge 11, but I sort of used the brute force way of solving it, by looping over each element and pushing them to an array and then returning the array.
Is there a better way to map the elements of a column of a 2D array?
below is my solution:

function lightColumn(column){
  var columnContents = [];
  columnNumber = convertColumn(column);
  for (var i = 0; i < GRID.length; i++){
    columnContents.push(GRID[i][columnNumber])  
  }
  return columnContents;
}

#2

I’m no expert for sure, but I don’t think that pushing your items into a freshly initialized array is ‘brute force’. That’s how I’ve done it and I feel like it’s a fine way to do things.


#3

The way you accomplished this is fine. You could have also used forEach to more concisely return an array of column elements. With ES6, you can also use for … of to iterate over arrays in a cleaner way.