let arrays = [ [ ' ', ' ', ' ' ], [ ' ', ' ', ' ' ], [ ' ', ' ', ' ' ] ]
console.log(arrays);
for(i = 0; i < arrays.length; i++){
arrays[i][(arrays.length - 1) - i] = '-'
}
console.log(arrays); //[ [ ' ', ' ', '-' ], [ ' ', '-', ' ' ], [ '-', ' ', ' ' ] ]
This is the result I want.
The code below has a different result.
let input = 6;
const diameter = input; //6
const centralValue = Math.ceil(diameter / 2); //3
const reverseArray = (array) => {return array.slice(0).reverse();} //어레이 뒤집어줌
// const makeUpperLeftArrays = function(centralValue){
// }
let createEmptyArray = (number) => {return new Array(number).fill(' ')} //빈 배열 생성
let emptyArray = createEmptyArray(centralValue);
let addEmptyArrays = function(array){
let addedEmptyArrays = [];
for(i = 1; i <= centralValue; i++){
addedEmptyArrays.push(array)
}
return addedEmptyArrays;
}
let addedEmptyArrays = addEmptyArrays(emptyArray);
let arrays = addedEmptyArrays
//[ [ ' ', ' ', ' ' ], [ ' ', ' ', ' ' ], [ ' ', ' ', ' ' ] ]
console.log(arrays);
for(i = 0; i < arrays.length; i++){
arrays[i][(arrays.length - 1) - i] = '-'
}
console.log(arrays);
please help...
I tried debugging, taking it out of function, changing the name, but it didn't work.