가이버2
개발 블로그
가이버2
전체 방문자
오늘
어제
  • 분류 전체보기 (172)
    • 교육 (115)
      • 백엔드 (14)
      • 프론트 (2)
      • 네트워크 관련 (4)
      • 데이터 관련 (3)
      • devops (3)
      • 그외 (3)
      • 알고리즘 (5)
      • 코테 (81)
    • 디버깅 (3)
      • 스프링 Data JPA (3)
      • JAVA (0)
    • 개발 편의 (8)
    • 기계 (25)
      • NAS (10)
      • ROUTER (0)
      • 맥북 (15)
    • 소프트웨어 (17)
      • WIN (4)
      • MAC (13)
      • LINUX (0)
    • 생활 (0)
      • 구매 (0)
      • 오월이 (0)
    • 링크 (3)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

  • naelonambul 개발 블로그 입니다.

인기 글

태그

  • SQL
  • intellij
  • Spring
  • ARM
  • 시놀로지
  • 가상화
  • 프로그래머스
  • 스프링
  • 윈도우
  • 인프런
  • WSL
  • 맥
  • Java
  • JS
  • 맥북
  • 코딩테스트
  • 맥미니
  • M1
  • SSD
  • M4

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
가이버2

개발 블로그

교육/코테

[프로그래머스] JS K번째수

2022. 5. 19. 16:19

https://programmers.co.kr/learn/courses/30/lessons/42748

 

코딩테스트 연습 - K번째수

[1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3]

programmers.co.kr

이거 때문에 오류남.

const array1 = [1, 30, 4, 21, 100000];
array1.sort();
console.log(array1);
// expected output: Array [1, 100000, 21, 30, 4]
function solution(array, commands) {
  var answer = [];
  for (let i = 0; i < commands.length; i++) {
    answer.push(logic(commands[i], array));
  }

  function logic(command, array) {
    let newArray = [];
    let nInt = 0;

    for (let i = 0; i < array.length; i++) {
      let front = command[0] - 1;
      let end = command[1] - 1;
      if (front <= i && i <= end) {
        newArray.push(array[i]);
      }
    }
    newArray.sort((a, b) => a - b);
    nInt = newArray[command[2] - 1];
    return nInt;
  }

  return answer;
}

'교육 > 코테' 카테고리의 다른 글

[프로그래머스]JS 체육복  (0) 2022.05.20
[프로그래머스]JS 모의고사  (1) 2022.05.20
[프로그래머스]JS 소수만들기  (0) 2022.05.19
[프로그래머스]JS 내적  (0) 2022.05.19
[프로그래머스]JS 음양 더하기  (0) 2022.05.19
    '교육/코테' 카테고리의 다른 글
    • [프로그래머스]JS 체육복
    • [프로그래머스]JS 모의고사
    • [프로그래머스]JS 소수만들기
    • [프로그래머스]JS 내적
    가이버2
    가이버2
    개인 개발 블로그 입니다.

    티스토리툴바