JS solution (better names & runs in console)


#1

(open/expand for formatted code)

function performOps(inputArray) {
  const lengthOfFirstArray = inputArray[0].length
  const list = []

  for (let i = 0; i < inputArray.length; i++) {
    const nestedList = new Array(lengthOfFirstArray)
    list.push(nestedList)

    for (let j = 0; j < lengthOfFirstArray; j++) {
      const subIndex = lengthOfFirstArray - 1 - j
      list[i][subIndex] = inputArray[i][j]
    }
  }
  return list
}

function run() {
  const input = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
  const result = performOps(input)

  for (let i = 0; i < result.length; i++) {
    for (let j = 0; j < result[i].length; j++) {
      console.log(result[i][j] + ' ')
    }
  }
}
run()