Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function myFunc(matrix) {
- let pairs = 0
- for (let r = 0; r < matrix.length; r++) {
- for (let c = 0; c < matrix[r].length; c++) {
- if (c + 1 < matrix[r].length) {
- if (matrix[r][c] === matrix[r][c + 1]) { pairs++ }
- }
- if (r + 1 < matrix.length) {
- if (matrix[r][c] === matrix[r + 1][c]) { pairs++ }
- }
- }
- }
- return pairs
- }
- console.log(myFunc([['test', 'yes', 'yo', 'ho'],
- ['well', 'done', 'yo', '6'],
- ['not', 'done', 'yet', '5']]
- ))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement