https://www.codewars.com/kata/55a2d7ebe362935a210000b2
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:
Given an array of integers your solution should find the smallest integer.
For example:
- Given [34, 15, 88, 2] your solution will return 2
- Given [34, -345, -1, 100] your solution will return -345
You can assume, for the purpose of this kata, that the supplied array will not be empty.
설명:
정수 배열이 주어지면 솔루션은 가장 작은 정수를 반환해야 합니다.
예를 들어:
- [34, 15, 88, 2]이 주어지면 솔루션은 2를 반환해야 합니다.
- [34, -345, -1, 100]이 주어지면 솔루션은 -345를 반환해야 합니다.
이 카타를 위해 제공된 배열이 비어있지 않은 것이라고 가정할 수 있습니다.
풀이
주어진 배열을 오름차순으로 정렬하고 가장 앞의 숫자를 반환했다.
코드
class SmallestIntegerFinder {
findSmallestInt(args) {
return args.sort((a, b) => a - b)[0];
}
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] String repeat (8 kyu) / JavaScript (0) | 2022.12.07 |
---|---|
[Codewars] Remove First and Last Character (8 kyu) / JavaScript (0) | 2022.12.06 |
[Codewars] Counting sheep... (8 kyu) / JavaScript (0) | 2022.12.03 |
[Codewars] Sum of two lowest positive integers (7 kyu) / JavaScript (0) | 2022.12.02 |
[Codewars] Complementary DNA (7 kyu) / JavaScript (0) | 2022.12.01 |
댓글