Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function makeRandomCharArr()
  2. {
  3.     var text = "";
  4.     var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  5.     var size = getRandomNumber(1, 15);
  6.  
  7.     for( var i=0; i < size; i++ )
  8.         text += possible.charAt(Math.floor(Math.random() * possible.length));
  9.  
  10.     return text.split('');
  11. }
  12.  
  13. function getRandomNumber(min, max) {
  14.     return Math.floor(Math.random() * (max - min) + min);
  15. }
  16.  
  17. function compareLengths(a, b) {
  18.     if (a > b) {
  19.         return b;
  20.     } else {
  21.         return a;
  22.     }
  23. }
  24.  
  25. var arr1 = makeRandomCharArr();
  26. var arr2 = makeRandomCharArr();
  27.  
  28. console.log(arr1);
  29. console.log(arr2);
  30.  
  31. for (var i = 0; i <= compareLengths(arr1.length, arr2.length); i += 1) {
  32.     if (arr1[i] > arr2[i]){
  33.         console.log('first is: ' + arr2);
  34.         break;
  35.     } else {
  36.         console.log('first is: ' + arr1);
  37.         break;
  38.     }
  39.     if (arr1.length > arr2.length) {
  40.         if (i === arr2.length - 1) {
  41.             console.log('first is: ' + arr2)
  42.             break;
  43.         }
  44.     } else if (arr1.length < arr2.length) {
  45.         if (i === arr1.length - 1) {
  46.             console.log('first is: ' + arr1)
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement