M
M
MANCHERA CHAN2021-08-29 12:56:39
Arrays
MANCHERA CHAN, 2021-08-29 12:56:39

How to crop a 2D array into a rectangle shape?

Who knows the function that would be able to cut a two-dimensional array in the form of a rectangle. That would be possible to specify the place from where to cut and to where.

or if anyone knows explain how to cut in the shape of a rectangle using this function

function CutMap(mat, x, y, w, h) {
        return mat.slice(y, y + h).map(function(row) {
            return row.slice(x, x + w)
        })
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-08-29
@MANCHERA

Look at the description of the slice and map methods and try to guess what exactly the code you provided does.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question