https://www.codewars.com/kata/5d5ee4c35162d9001af7d699
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 2D ( nested ) list ( array, vector, .. ) of size m * n, your task is to find the sum of the minimum values in each row.
For Example:
[ [ 1, 2, 3, 4, 5 ] # minimum value of row is 1
, [ 5, 6, 7, 8, 9 ] # minimum value of row is 5
, [ 20, 21, 34, 56, 100 ] # minimum value of row is 20
]
So the function should return 26 because the sum of the minimums is 1 + 5 + 20 = 26.
Note: You will always be given a non-empty list containing positive values.
ENJOY CODING :)
코드
function sumOfMinimums(arr) {
let sum = 0;
for(let i = 0; i < arr.length; i++){
sum += Math.min(...arr[i]);
}
return sum;
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Printing Array elements with Comma delimiters (8 kyu) / JavaScript (0) | 2023.04.04 |
---|---|
[Codewars] Add Length (8 kyu) / JavaScript (0) | 2023.04.03 |
[Codewars] The Feast of Many Beasts (8 kyu) / JavaScript (0) | 2023.04.01 |
[Codewars] Name Shuffler (8 kyu) / JavaScript (0) | 2023.03.31 |
[Codewars] Directions Reduction (5 kyu) / JavaScript (0) | 2023.03.30 |
댓글