I don know what am I doing wrong.
Write a function named rotateArt that takes two (2) parameters: imageArray and rotation. (a) imageArray is a 2D array of any dimension containing an ASCII art “image.” (b) rotation is a value that is one of the following values: 0, 90, 180, 270, 360, -90, -180, -270. A positive value indicates a rotation in the clockwise direction. A negative value indicates a rotation in the counter-clockwise direction. A value of 0 or 360 means that no rotation is to take place, but that the image is to be mirrored or flipped around the vertical axis
function rotateChar(char,rotation){
let rowLookup = ['^','v','>','<','|','-','|','\\','/','`','~','[','=','_'];
let colLookup = [-270,-180,-90,0,90,180,270];
let rotations = [
['>','v','<','^','>','v','<'],
['<','^','>','v','<','^','>'],
['v','<','^','>','v','<','^'],
['^','>','v','<','^','>','v'],
['-','|','-','|','-','|','-'],
['|','-','|','-','|','-','|'],
['_','|','_','|','_','|','_'],
['/','\\','/','\\','/','\\','/'],
['\\','/','\\','/','\\','/','\\'],
['~','`','~','`','~','`','~'],
['`','~','`','~','`','~','`'],
['=','[','=','[','=','[','='],
['[','=','[','=','[','=','['],
];
if (rowLookup.indexOf(char)=== -1 || colLookup.indexOf(rotation)=== -1) {
return char;
} else {
return rotations[rowLookup.indexOf(char)][colLookup.indexOf(rotation)];
}
}
function rotateArt(imageArray,rotation){
rotation = parseInt(rotation);
let newArray = [];
let width = 0, height = 0;
let cols = [-270,-180,-90,0,90,180,270];
let rowLookup = ['^','v','>','<','|','-','|','\\','/','`','~','[','=','_'];
switch (rotation){
case 90:
width = cols;
height = rowLookup;
for (let i =0; i < width; i++){
let newRow = [];
for (let j =0; j < height; j++){
newRow.push('x');
}
newArray.push(newRow);
}
for (let i = 0; i < rowLookup; i++){
for (let j =0; j < cols; j++){
newArray[j][rowLookup - 1 - i] = rotateChar(imageArray[i][j],rotation);
}
}
break;
default:
break;
}
return newArray;
}
Aucun commentaire:
Enregistrer un commentaire