JavaScript: Matrix mirroring

Last update: 09 Jun 23:20
1
Student
100%
Completion rate

arrays.js

Write and export as default a function that takes a two-dimensional array (matrix) and returns an array, where the right half of the matrix is a mirror copy of the left one, symmetrical to its vertical axis. To keep it simple, suppose that the matrix always has an even number of columns and their number is always equal to the number of rows.

Examples

getMirrorMatrix([
  [11, 12, 13, 14],
  [21, 22, 23, 24],
  [31, 32, 33, 34],
  [41, 42, 43, 44],
]);

//  [
//     [11, 12, 12, 11],
//     [21, 22, 22, 21],
//     [31, 32, 32, 31],
//     [41, 42, 42, 41],
//  ]

Tips

  • Try to complete the challenge without using built-in array methods. Except for push() method that adds elements to the array

For full access to the challenge you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests