being my best self, as a software engineer, in the age of the Aquarius

VISUALIZING PROCESS:
Provided Image: [[1,1,0],[1,0,1],[0,0,0]]
Flipping Image: [[0,1,1],[1,0,1],[0,0,0]]Inverted Image: [[1,0,0],[0,1,0],[1,1,1]]Resulting Image: [[1,0,0],[0,1,0],[1,1,1]]Executed in JavaScript:
var flipAndInvertImage = function(image) {
let final = [];
console.log('first loop', final)
for(let i =0; i<image.length; i++){
final.push([]);
console.log('looping process', final)
for(let j=image[i].length-1; j>=0; j--) {
final[i].push(image[i][j] ? 0:1)
}
}
console.log('outside loop', final)
return final
};
With console.log's:
first loop [ [] ]
looping process [ [ 1 ] ]
looping process [ [ 1, 0 ] ]
looping process [ [ 1, 0, 0 ] ]
ending of loop [ [ 1, 0, 0 ] ]
first loop [ [ 1, 0, 0 ], [] ]
looping process [ [ 1, 0, 0 ], [ 0 ] ]
looping process [ [ 1, 0, 0 ], [ 0, 1 ] ]
looping process [ [ 1, 0, 0 ], [ 0, 1, 0 ] ]
ending of loop [ [ 1, 0, 0 ], [ 0, 1, 0 ] ]
first loop [ [ 1, 0, 0 ], [ 0, 1, 0 ], [] ]
looping process [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 1 ] ]
looping process [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 1, 1 ] ]
looping process [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 1, 1, 1 ] ]
ending of loop [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 1, 1, 1 ] ]
outside loop [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 1, 1, 1 ] ]

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store