FrontEnd/프로그래머스
[JS] 바탕화면 정리
정_민_규
2023. 3. 21. 20:21
728x90
정리해야 하는 폴더들의 x,y 좌표들을 모두 구한뒤, 각 좌표의 최솟값을 시작 좌표로 두고, 각 좌표들의 최댓값을 끝 좌표로 두면 정답을 구할 수 있다.
function solution(wallpaper) {
const rowLen = wallpaper[0].length
const colLen = wallpaper.length
const xList =[]
const yList = []
for (let i=0 ; i<colLen ; i++){
for (let j=0 ; j<rowLen ; j++){
if (wallpaper[i][j]==="#"){
xList.push(j)
yList.push(i)
}
}
}
let answer = [Math.min(...yList),Math.min(...xList),Math.max(...yList)+1,Math.max(...xList)+1];
return answer;
}
728x90