
// You should implement your task here.

module.exports = function towelSort (matrix) {
  let resultArray = [];
  if (matrix) {
    let nestedArray;
      for (let i = 0; i < matrix.length; i++) {
        if( i % 2 !== 0) {
          nestedArray = matrix[i].reverse();
        } else {
          nestedArray = matrix[i];
        }
        
        resultArray = resultArray.concat(nestedArray);
    }
  }
  return resultArray;
};
