Advertisement
BonchoBelutov

Lexicographically comparison -the true one

Jun 23rd, 2016
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(args) {
  2.     var arr = args[0].split("\n");
  3.  
  4.     var array1 = arr[0].trim().toLowerCase();
  5.     var array2 = arr[1].trim().toLowerCase();
  6.  
  7.     var n1 = array1.length;
  8.     var n2 = array2.length;
  9.  
  10.     if (n1 < n2) {
  11.         console.log("<");
  12.         return;
  13.     }
  14.     else if (n1 > n2) {
  15.         console.log(">");
  16.         return;
  17.     }
  18.     else {
  19.         if (n1 === n2 && array1.localeCompare(array2)===0) {
  20.  
  21.             console.log("=");
  22.             return;
  23.         }
  24.         else {
  25.             for (var i = 0; i < n1; i++) {
  26.                 if (array1[i].localeCompare(array2[i])===-1) {
  27.                     console.log("<");
  28.                     return;
  29.                 }
  30.                 if (array1[i].localeCompare(array2[i])===1) {
  31.                     console.log(">");
  32.                     return;
  33.                 }
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement