https://www.codewars.com/kata/586f6741c66d18c22800010a
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:
Your task is to make function, which returns the sum of a sequence of integers.
The sequence is defined by 3 non-negative values: begin, end, step (inclusive).
If begin value is greater than the end, function should returns 0
Examples
2,2,2 --> 2
2,6,2 --> 12 (2 + 4 + 6)
1,5,1 --> 15 (1 + 2 + 3 + 4 + 5)
1,5,3 --> 5 (1 + 4)
This is the first kata in the series:
- Sum of a sequence (this kata)
- Sum of a Sequence [Hard-Core Version]
코드
const sequenceSum = (begin, end, step) => {
let result = 0;
for(let i = begin; i <= end; i += step){
result += i;
}
return result;
};
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Double Char (8 kyu) / JavaScript (0) | 2023.03.01 |
---|---|
[Codewars] Training JS #1: create your first JS function and print "Hello World!" (8 kyu) / JavaScript (0) | 2023.02.28 |
[Codewars] Snail (4 kyu) / JavaScript (0) | 2023.02.26 |
[Codewars] DNA to RNA Conversion (8 kyu) / JavaScript (0) | 2023.02.25 |
[Codewars] Valid Braces (6 kyu) / JavaScript (0) | 2023.02.24 |
댓글