Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Thanks HackJack, it's funny how terrible I am at reading the details. If I would have looked at the numbers listed and realized they skipped some numbers. Probably wouldn't be as hard as I made it
This comment is hidden because it contains spoiler information about the solution
You will be given an ordered list of individual integers. You need to return the list of integers as a string in a format of a range. But how do you explain a range? Well, according to this kata a list of integers can be written as a range if (1) the numbers in the given ordered list are consecutive on the number line, for example:- 1,2,3. (2) there are 3 or more than 3 consecutive numbers in the list.
What qualifies as a range?
[1,2,3,4] qualifies as a range and can be written as "1-4". (first and last elements are inclusive)
[6,7] does not qualify as a range, because there are less than 3 consecutive numbers in the list.
[9,10,11] qualifies as a range and can be written as "9-11".
[-3,-2,-1] qualifies as a range and can be written as "-3--1".
What you are supposed to do?
Given an ordered list of integers, if the integers can be written as a range then return them as range, else return them as integers separated by comma. You must return all the given integers in the list whether as a range (if it qualifies as a range) or just plain old integers.
For example:-
Input:- [1,3,5,7,9]
Output:- "1,3,5,7,9"
Input:- [1,2,3,4,5,6,7]
Output:- "1-7"
Input:- [1,2,3,8,9,10]
Ouput:- "1-3,8-10"
I hope this helps.
what part of the task did you specifically not understand? I ask because it is hard to explain without simply repeating the description. You are given a list of numbers, and you are supposed to identify consecutive number ranges (adjacent numbers that differ by exactly 1). In the resulting string, individual numbers are returned as is, and ranges of consecutive numbers (with at least 3 or more) are to be transformed into
"first-last"
.can someone explain this problem to me?