Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function filter(input) {
- let n = Number(input.pop());
- let matrix = input
- .map(x => Array.from(x))
- .map(x => x.filter(x => x != ' '))
- .map(x => x.map(Number));
- for (let row = 0; row < matrix.length; row++) {
- for (let col = 0; col < matrix[row].length; col++) {
- let a = matrix[row][col];
- for (let i = 1; i < n; i++) {
- let b = matrix[row][i + col];
- if (a == b) {
- matrix[row][i + col] = ' ';
- if (n - i == 1) {
- matrix[row][col] = ' ';
- }
- }
- }
- }
- }
- //console.log([...matrix].join('\n'));
- }
- filter([
- '3 3 3 2 5 9 9 9 9 1 2',
- '1 1 1 1 1 2 5 8 1 1 7',
- '7 7 1 2 3 5 7 4 4 1 2',
- '2'
- ]);
Add Comment
Please, Sign In to add comment