Home > Web Front-end > JS Tutorial > Lucky Numbers in a Matrix

Lucky Numbers in a Matrix

PHPz
Release: 2024-07-19 17:45:40
Original
901 people have browsed it

Lucky Numbers in a Matrix

*This code describes how to find a lucky number in a matrix. *

const luckyNumber = (matrix)=>{
let num = []
for (let i = 0; i < matrix.length; i++) {
let arr = matrix[i];
let rowMax = Math.min(...arr);
let columnIndex = matrix[i].indexOf(rowMax);
let column = matrix.map((row) => row[columnIndex]);
let columnMax = Math.max(...column);
if (rowMax === columnMax) {
num.push(rowMax);
}
}
return num;
}

The above is the detailed content of Lucky Numbers in a Matrix. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template