티스토리 뷰
Solution in JavaScript
const scores = [10, 5, 20, 20, 4, 5, 2, 25, 1];
function breakingRecords(scores) {
let [max, min] = [scores[0], scores[0]]; //중복배열로 선언
let [maxCount, minCount] = [0, 0];
for (let i = 1; i < scores.length; i++) {
if (scores[i] > max) { //array로 넣어야지...
max = scores[i];
maxCount++
}
if (scores[i] < min) {
min = scores[i];
minCount++
}
}
return [maxCount, minCount]; //두개 이상의 값 return할 때 array로 선언하고 리턴하기.
}
const result = breakingRecords(scores);
console.log(result);
처음에 max와 min을 숫자 0으로 초기화했어서 실패;;; index 0으로 시작하고 i값을 1부터 시작해서 비교!
Reference
www.hackerrank.com/challenges/breaking-best-and-worst-records/problem
'Algorithms' 카테고리의 다른 글
Birthday Chocolate (0) | 2020.09.11 |
---|---|
Divisible Sum Pairs (0) | 2020.09.05 |
Apple and Orange (0) | 2020.08.24 |
Grading Students (0) | 2020.08.22 |
Time Conversion (0) | 2020.08.22 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- HashMap
- hackerrank solution
- math.max
- Object type casting
- repeat()
- rest parameter
- hackerrank javascript
- Collection Framework
- string class in java
- C++
- Javascript Algorithm
- compareTo()
- javascript
- HackerRank Algorithm
- math.abs
- ... in Javascript
- 프로그래머스 알고리즘문제
- substring()
- algorithm
- 알고리즘
- equals()
- easy javascript algorithm
- 프로그래머스
- easy algorithm
- hackerrank javascript solution
- java
- spring boot application
- hackerrank
- code refactoring
- 프로그래머스 알고리즘
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함