https://www.codewars.com/kata/5899dc03bc95b1bf1b0000ad
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 a set of numbers, return the additive inverse of each. Each positive becomes negatives, and the negatives become positives.
invert([1,2,3,4,5]) == [-1,-2,-3,-4,-5]
invert([1,-2,3,-4,5]) == [-1,2,-3,4,-5]
invert([]) == []
You can assume that all values are integers. Do not mutate the input array/list.
코드
function invert(array) {
return array.map(el => el * -1);
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Reverse words (7 kyu) / JavaScript (0) | 2023.01.18 |
---|---|
[Codewars] Beginner Series #1 School Paperwork (8 kyu) / JavaScript (0) | 2023.01.17 |
[Codewars] Human Readable Time (5 kyu) / JavaScript (0) | 2023.01.15 |
[Codewars] Find the divisors! (7 kyu) / JavaScript (0) | 2023.01.13 |
[Codewars] Opposites Attract (8 kyu) / JavaScript (0) | 2023.01.12 |
댓글