Home  >  Article  >  Web Front-end  >  Lucky Numbers in a Matrix

Lucky Numbers in a Matrix

PHPz
PHPzOriginal
2024-07-19 17:45:40896browse

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!

Statement:
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
Previous article:About Driver.jsNext article:About Driver.js