Click here to Skip to main content
15,919,778 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: loading image before loading video on page Pin
twseitex5-May-13 7:59
twseitex5-May-13 7:59 
QuestionI cant download the source code in the following projet Pin
Baturay E.H.AHMAD27-Apr-13 9:17
Baturay E.H.AHMAD27-Apr-13 9:17 
AnswerRe: I cant download the source code in the following projet Pin
NotPolitcallyCorrect27-Apr-13 12:03
NotPolitcallyCorrect27-Apr-13 12:03 
QuestionjQuery Question Pin
BobInNJ26-Apr-13 13:05
BobInNJ26-Apr-13 13:05 
AnswerRe: jQuery Question Pin
dusty_dex26-Apr-13 13:28
dusty_dex26-Apr-13 13:28 
GeneralRe: jQuery Question Pin
Richard Deeming29-Apr-13 2:31
mveRichard Deeming29-Apr-13 2:31 
GeneralRe: jQuery Question Pin
dusty_dex29-Apr-13 3:28
dusty_dex29-Apr-13 3:28 
GeneralRe: jQuery Question Pin
Jasmine25011-May-13 8:27
Jasmine25011-May-13 8:27 
AnswerRe: jQuery Question Pin
Richard MacCutchan26-Apr-13 22:32
mveRichard MacCutchan26-Apr-13 22:32 
AnswerRe: jQuery Question Pin
Graham Breach26-Apr-13 23:00
Graham Breach26-Apr-13 23:00 
AnswerRe: jQuery Question Pin
Member 5654516-May-13 0:44
Member 5654516-May-13 0:44 
QuestionJS Question Pin
Hakan Bulut18-Apr-13 3:31
Hakan Bulut18-Apr-13 3:31 
AnswerRe: JS Question Pin
Sandeep Mewara18-Apr-13 4:55
mveSandeep Mewara18-Apr-13 4:55 
GeneralRe: JS Question Pin
Hakan Bulut18-Apr-13 6:52
Hakan Bulut18-Apr-13 6:52 
AnswerRe: JS Question Pin
dusty_dex18-Apr-13 6:18
dusty_dex18-Apr-13 6:18 
AnswerRe: JS Question Pin
Dennis E White18-Apr-13 7:34
professionalDennis E White18-Apr-13 7:34 
GeneralRe: JS Question Pin
dusty_dex18-Apr-13 7:42
dusty_dex18-Apr-13 7:42 
GeneralRe: JS Question Pin
Hakan Bulut19-Apr-13 2:32
Hakan Bulut19-Apr-13 2:32 
AnswerRe: JS Question Pin
dusty_dex18-Apr-13 7:41
dusty_dex18-Apr-13 7:41 
GeneralRe: JS Question Pin
Hakan Bulut18-Apr-13 20:59
Hakan Bulut18-Apr-13 20:59 
GeneralRe: JS Question Pin
dusty_dex18-Apr-13 21:36
dusty_dex18-Apr-13 21:36 
GeneralRe: JS Question Pin
Hakan Bulut18-Apr-13 22:10
Hakan Bulut18-Apr-13 22:10 
GeneralRe: JS Question Pin
dusty_dex18-Apr-13 22:14
dusty_dex18-Apr-13 22:14 
GeneralRe: JS Question Pin
Hakan Bulut19-Apr-13 2:30
Hakan Bulut19-Apr-13 2:30 
GeneralRe: JS Question Pin
dusty_dex19-Apr-13 3:32
dusty_dex19-Apr-13 3:32 
Small change to previous code, see use of var t;
JavaScript
// **NEW** add leading zero to numbers < 10
function zeroAdjust(n) {
    var t = "0"+n;
    return t.substring(t.length-2,t.length);
}

// these also need leading zero if < 10
var arrIns  = [ "01","21","24","28","42","48",
                "12","23","34","36","37","46",
                "03","18","19","25","44","45"  ];

var allLucky = arrIns.toString();

var arrLot  = [];
var arr     = [];
var count   = 0;
var t;

for(var i=1; i<50; i++)
  {
    // compare t with all lucky numbers
    t = zeroAdjust(i);
    if (allLucky.indexOf(t) == -1 ) {
      arr[count] = t; // arr[] = "nn"
      count++;
    }
  } // for-loop

document.write("arr[]:"+ arr.toString);
document.write("<br>");
document.write("length of arr[] ="+ count +"<br>");


*NEW*
JavaScript
function sort(ref) {
  var a = [];
  var i;

  //== conversion function (only to sort) ========================================
  function strToUcc( s ) {
    if (s.length < 2) {
      return String.fromCharCode(s.charCodeAt(0)-48);
    } else {
      return String.fromCharCode( (s.charCodeAt(1)-48)+((s.charCodeAt(0)-48)*10) );
    }
  }

  //== conversion function as "nn" string
  function uccToStr( s ) {
    var tmp = s.charCodeAt(0);
    var lo = tmp % 10;
    var hi = (tmp-lo) / 10;

    return String.fromCharCode(hi+48)+String.fromCharCode(lo+48);
  }
  //=================================================================================

  // char-code from "nn"
  i=0;
  while (i < ref.length) {
    a[i] = strToUcc( ref[i] );
    i++;
  }

  a.sort(); // SORT 

  // back to "nn"
  i=0;
  while (i < ref.length) {
    ref[i] = uccToStr( a[i] );
    i++;
  }

} // fn-sort

sort(arrIns); 

document.write("Sorted:"+ arrIns.toString());

"It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan

That's what machines are for.

Got a problem?
Sleep on it.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.