Larger Number

Problem

Write a program that takes N (1<=N<=100) integers as input and outputs only the number that is greater than the number immediately preceding itself. (The first number is unconditionally printed.)

input

A natural number N is given in the first line, and N integers are entered in the next line.

6
7 3 9 5 6 12

output

Only the number greater than the number immediately preceding itself is printed on a single line.

7 9 6 12

Solution

using filter()

function solution(arr) {
	let answer = [arr[0]];

	answer = [...answer, ...arr.filter((v, i) => arr[i] > arr[i - 1])];

	return answer;
}

using for in...

function solution(arr) {
	let answer = [];

	answer.push(arr[0]);

	for (let i = 1; i < arr.length; i++) {
		if (arr[i] > arr[i - 1]) answer.push(arr[i]);
	}

	return answer;
}