JSFiddle - React, Tailwind, and code Playground
by Nidhi Patel
JavaScript
/* function invertHorizontally(arr){
arr[0].map((element, index)=>{ //[1,1,0]
arr.map(element_two => element_two[index])
})
}
function invertVertically(arr){
invertHorizontally(arr.reverse()) // [[1,1,0],[1,0,1],[0,0,0]] => [[0,0,0], [1,0,1], [1,1,0]]
}
*/
/* Input: [[1,1,0],[1,0,1],[0,0,0]] => [0,0,1] => [1,0,0]
Output: [[1,0,0],[0,1,0],[1,1,1]] */
function invertArray(arr){
for(var i=0; i<arr.length; i++){
arr[i].reverse()
arr[i] = arr[i].map((el, index)=>{
if(el===0){
el=1
}
else{
el=0
}
})
}
return arr
}
var hero = {
_name: 'John Doe',
getSecretIdentity: function (){
return this._name;
}
};
var indentity = hero.getSecretIdentity