https://www.codewars.com/kata/57f609022f4d534f05000024
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:
You are given an odd-length array of integers, in which all of them are the same, except for one single number.
Complete the method which accepts such an array, and returns that single different number.
The input array will always be valid! (odd-length >= 3)
Examples
[1, 1, 2] ==> 2
[17, 17, 3, 17, 17, 17, 17] ==> 3
코드
function stray(numbers) {
const set = [...new Set(numbers)];
return numbers.filter(el => el === set[0]).length === 1 ? set[0] : set[1];
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Weight for weight (5 kyu) / JavaScript (0) | 2023.04.23 |
---|---|
[Codewars] Don't give me five! (7 kyu) / JavaScript (0) | 2023.04.22 |
[Codewars] Twice as old (8 kyu) / JavaScript (0) | 2023.04.20 |
[Codewars] Super Duper Easy (8 kyu) / JavaScript (0) | 2023.04.19 |
[Codewars] The Hashtag Generator (5 kyu) / JavaScript (0) | 2023.04.19 |
댓글