강의

멘토링

커뮤니티

Inflearn Community Q&A

rhkdtjd124829's profile image
rhkdtjd124829

asked

Introduction to Javascript Algorithm Problem Solving (Coding Test Preparation)

1. Print large numbers

filter를 이용한 풀이

Written on

·

413

0

강의 보기전 제가 문제를 제대로 이해 했는지 모르겠으나,

첫줄6과 7을 비교를 처음 시작, 그 이후 부터 자신의 바로 앞 수보다 큰 수만 출력 이렇게 이해해서 filter와 삼항연산자를 이용하여 풀어보았습니다.

function solution(num, array) {
  return array.filter((v, index) =>
  index === 0 ? v > num : array[index] > array[index - 1]
  );
}

console.log(solution(6, [7, 3, 9, 5, 6, 12]));

 

javascript코딩-테스트

Answer 1

0

rhkdtjd124829님의 프로필 이미지
rhkdtjd124829
Questioner

첫번째 숫자는 무조건 출력이니까

function solution(num, array) {
  return array.filter((v, index) =>
  index === 0 ? v : array[index] > array[index - 1]
  );
}

console.log(solution(6, [7, 3, 9, 5, 6, 12]));

코드를 이렇게 수정 해야 될것 같습니다.

rhkdtjd124829's profile image
rhkdtjd124829

asked

Ask a question