task/10-katas-1-tasks.js
/**
 * Returns the string expression of the specified ordered list of integers.
 *
 * A format for expressing an ordered list of integers is to use a comma separated list of either:
 *   - individual integers
 *   - or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'.
 *     (The range includes all integers in the interval including both endpoints)
 *     The range syntax is to be used only for, and for every range that expands to more than two values.
 *
 * @params {array} nums
 * @return {bool}
 *
 * @example
 *
 * [ 0, 1, 2, 3, 4, 5 ]   => '0-5'
 * [ 1, 4, 5 ]            => '1,4,5'
 * [ 0, 1, 2, 5, 7, 8, 9] => '0-2,5,7-9'
 * [ 1, 2, 4, 5]          => '1,2,4,5'
 */
Returns the string expression of the specified ordered list of integers.
A format for expressing an ordered list of integers is to use a comma separated list of either:
- individual integers
- or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'.
(The range includes all integers in the interval including both endpoints)
The range syntax is to be used only for, and for every range that expands to more than two values.

@params {array} nums
@return {bool}

@example


Returns the string expression of the specified ordered list of integers . A format for expressing an ordered list of integers is to use a comma separated list of either : - individual integers - or a range of integers denoted by the starting integer separated from the end integer in the range by a dash ' - ' . ( The range includes all integers in the interval including both endpoints ) The range syntax is to be used only for and for every range that expands to more than two values . @params { array } nums @return { bool } @example
function extractRanges(nums) {
    let result='';
    for(let i=0;i<nums.length;i++){
        let start=i;
        while(nums[++i]===nums[i-1]+1){ }
        i--;
        if(i-start>1){
            result+=nums[start]+'-'+nums[i];
        }else{
            result+=(i-start)===0?nums[i]:nums[start]+','+nums[i];
        }
        result+=',';
    }
    return result.slice(0, -1); 
}
function extractRanges ( nums ) { let result = '' ; for ( let i = 0 ; i < nums . length ; i ++ ) { let start = i ; while ( nums [ ++ i ] === nums [ i - 1 ] + 1 ) { } i -- ; if ( i - start > 1 ) { result += nums [ start ] + '-' + nums [ i ] ; } else { result += ( i - start ) === 0 ? nums [ i ] : nums [ start ] + ',' + nums [ i ] ; } result += ',' ; } return result . slice ( 0 , - 1 ) ; }
Returns the string expression of the specified ordered list of integers.
Returns the string expression of the specified ordered list of integers .