전체 글143 [정렬/javascript] 프로그래머스 가장 큰 수 참고한 풀이 function solution(numbers) const answer = numbers //map으로 numbers를 일관되게 string으로 변환한다. .map(numbers -> String(numbers)) .sort((a,b) => (b+a) - (a+b)) .join(''); //0인 경우는 제외해야 하니 삼항연산자 사용 return answer[0] === '0' ? '0' : answer; 내가 이해한 풀이 function solution(numbers) { const answer = numbers.map(number => String(number)); // map을 돌며 numbers 배열을 문자열로 생성 answer.sort((a, b) => (b + a) - (a + b).. 2023. 9. 1. [정렬/javascript] 프로그래머스 K번째 수 참고한 풀이 function solution(array, commands) { var answer = []; for(var i=0; i{return a-b}); answer.push(list[commands[i][2]-1]); } return answer; } 내가 이해한 풀이 function solution(array, commands) { const result = []; for(const command of commands) { const [start, end, position] = command; // command를 분해 const sliced = array.slice(start - 1, end); // slice에서 -1 하는 것을 기억할 것 const sorted = sliced.sort((.. 2023. 9. 1. [BFS/javascript] 프로그래머스 게임 맵 최단거리 최단거리는 BFS로 function solution(maps) { let answer = 1; // 최단 경로 길이를 저장하는 변수 let visited = maps; // 방문 여부 let queue = []; // BFS는 큐 const dx = [-1, 1, 0, 0]; // x 방향 상하좌우 const dy = [0, 0, -1, 1]; // y 방향 상하좌우 const n = maps.length; // 맵의 행 수 const m = maps[0].length; // 맵의 열 수 queue.push([0, 0]); // 시작 지점을 큐에 추가 visitied[0][0] = 0; // 시작 지점을 방문한 것으로 표시 while (queue.length > 0) { // 큐가 빌 때까지 반복 let.. 2023. 8. 25. [JS] 프로그래머스 명예의 전당 (1) function solution(k, score) { // 명예의 전당 배열 const hour = [] // 결괏값 const result = [] // 모든 점수 순회 for(let i = 0; i Math.min(...honor)) { // 가장 작은 수를 이번 점수와 교체 후 내림차순 정렬 honor.pop() honor.push(score[i]) honor.sort((a,b) => b-a) } // 결괏값에 명예의 전당 중 최하위 점수 입력 result.push(honor.at(-1)).. 2023. 8. 18. 이전 1 ··· 3 4 5 6 7 8 9 ··· 36 다음