code: function flatten(matrix) {
      const res = [];
  
      // If the given matrix is not a matrix but a scalar.
      if (!Array.isArray(matrix)) {
          matrix = [
              [matrix]
          ];
      }
  
      matrix.forEach((row) => {
          // If the given matrix is a vector.
          if (!Array.isArray(row)) {
              row = [row];
          }
  
          row.forEach((elem) => {
              res.push(elem.real);
              res.push(elem.imag);
          });
      });
      return res;
  }
docs: flatten returns a list which flatten the given matrix.