Guest User

Untitled

a guest
Jan 15th, 2010
25
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function assert(a,b){
  2.     if (a !== b){
  3.         throw "Assertion fail! " + a + " != " + b;
  4.     }
  5. }
  6.  
  7. function getLastRevision(revs, branch){
  8.     var ind = branch.lastIndexOf(".");
  9.     var base = branch.slice(0, ind-1) + branch.slice(ind+1);
  10.    
  11.     function getTail(rev){
  12.         if(rev.indexOf(base) === 0){
  13.             return parseInt(rev.slice(base.length + 1), 10);
  14.         }
  15.     }
  16.    
  17.     var max = Number.MIN_VALUE;
  18.     for (var i=0; i < revs.length; i++){
  19.         var tail = getTail(revs[i]);
  20.         if(tail && tail > max){
  21.             max = tail;
  22.         }
  23.     }
  24.    
  25.     return base + "." + max;
  26. }
  27.  
  28. revs = ["1.18", "1.19","1.20","1.21","2.50",
  29.         "1.18.2.1", "1.18.2.2","1.18.2.3","1.18.2.6", "1.19.2.6",
  30.         "1.18.2.1.3.1", "1.18.2.1.3.2","1.18.2.1.3.3","1.18.2.1.3.61","1.18.3.1.3.6"]
  31.  
  32. assert(getLastRevision(revs, "1.18.0.2"), "1.18.2.6")
  33. assert(getLastRevision(revs, "1.18.2.1.0.3"), "1.18.2.1.3.61")
RAW Paste Data