Skip to content

Instantly share code, notes, and snippets.

@basekays
Created June 19, 2018 18:42
Show Gist options
  • Select an option

  • Save basekays/815e343899c1ae38a7f3ed430b16a074 to your computer and use it in GitHub Desktop.

Select an option

Save basekays/815e343899c1ae38a7f3ed430b16a074 to your computer and use it in GitHub Desktop.
//input = array of string
//output = array of string
// test case
// [[1,1,0],[1,0,1],[0,0,0]]
// [[1,0,0],[0,1,0],[1,1,1]]
function flipAndInvertImage(array) {
var result = [];
//horizontal flip
for (var i = 0; i < array.length; i++) {
var modified = [];
for (var j = array[i].length-1; j >= 0; j--) {
modified.push(array[i][j]);
}
result.push(modified);
}
//inversion
console.log('result', result);
for (var k = 0; k < result.length; k++) {
for (var l = 0; l < result[k].length; l++) {
if (result[k][l] == 0) {
result[k][l] = 1;
} else if (result[k][l] == 1) {
result[k][l] = 0;
}
}
}
return result;
}
flipAndInvertImage([[1,1,0],[1,0,1],[0,0,0]]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment