Ad
  • Default User Avatar

    Why did you choose

    [version1.length, version2.length].sort()[1]; 
    

    over the classical :

    Math.max(version1.length, version2.length);
    

    ?

  • Default User Avatar
    function solution(list){
      // takes care of undefined or empty lists
      if (!list || list === []) return "";
      // init run
      var s = [], curr = [list[0]], i = 1, l = list.length;
      for (; i<=l; i++) {
        // checks if current value is consecutive to the last one in our current run
        if (list[i] === curr[curr.length -1] + 1) {curr.push(list[i]); continue;}
        // otherwise if current run is less than 3 consecutives values
        // we push all of them in our solution
        if (curr.length < 3) {s = s.concat(curr);} 
        // otherwise we push range value "14-18"
        else {s.push(curr[0] + "-" + curr[curr.length -1]);}
        // starts new current run
        curr = [list[i]];  
      }
      return s.join(",");
    }
    
  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    if you have the array then you have the comma separated list (arr.join(","))