cortez

Neighbours

Nov 5th, 2012
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function checkIfBigger(n, array) {
  2.  
  3.     var index = parseInt(n);
  4.     var arrParsed = parseArr(array);
  5.     var arr = arrParsed.split(",");
  6.     var output = "";
  7.  
  8.    
  9.     if(index == 0) {
  10.  
  11.         if(arr.length != 1) {
  12.  
  13.             if(parseInt(arr[index]) > parseInt(arr[index + 1])) {
  14.  
  15.                 output = "No left neighbour, but <span style='color: red;'>BIGGER</span> than the right neighbour!";
  16.             }
  17.             else if(parseInt(arr[index]) == parseInt(arr[index + 1])) {
  18.  
  19.                 output = "No left neighbour and <span style='color: red;'>EQUAL</span> to the right neighbour!";
  20.             }
  21.             else {
  22.  
  23.                 output = "No left neighbour and <span style='color: red;'>SMALLER</span> than the right neighbour!";
  24.             }
  25.         }
  26.         else {
  27.  
  28.             output = "No neighbours!";
  29.         }
  30.     }
  31.     else if(index == (arr.length - 1)) {
  32.  
  33.         if(arr.length != 1) {
  34.  
  35.             if(parseInt(arr[index]) > parseInt(arr[index - 1])) {
  36.  
  37.                 output = "No right neighbour, but <span style='color: red;'>BIGGER</span> than the left neighbour!";
  38.             }
  39.             else if(parseInt(arr[index]) == parseInt(arr[index - 1])) {
  40.  
  41.                 output = "No right neighbour and <span style='color: red;'>EQUAL</span> to the left neighbour!";
  42.             }
  43.             else {
  44.  
  45.                 output = "No right neighbour and <span style='color: red;'>SMALLER</span> than the left neighbour!";
  46.             }
  47.         }
  48.         else {
  49.  
  50.             output = "No neighbours!";
  51.         }
  52.     }
  53.     else if(index > 0 && index < (arr.length - 1)) {
  54.  
  55.         if(arr[index] > arr[index - 1]) {
  56.  
  57.             if(arr[index] > arr[index + 1]) {
  58.  
  59.                 output = "The number is <span style='color: red;'>BIGGER</span> than its two neighbours!";
  60.             }
  61.             else if(arr[index] < arr[index + 1]) {
  62.  
  63.                 output = "The number is <span style='color: red;'>BIGGER</span> than its left neighbour, but <span style='color: red;'>SMALLER</span> than its right neighbour!";
  64.             }
  65.             else {
  66.  
  67.                 output = "The number is <span style='color: red;'>BIGGER</span> than its left neighbour and <span style='color: red;'>EQUAL</span> to its right neighbour!";
  68.             }
  69.         }
  70.         if(arr[index] < arr[index - 1]) {
  71.  
  72.             if(arr[index] < arr[index + 1]) {
  73.  
  74.                 output = "The number is <span style='color: red;'>SMALLER</span> than its two neighbours!";
  75.             }
  76.             else if(arr[index] > arr[index + 1]) {
  77.  
  78.                 output = "The number is <span style='color: red;'>SMALLER</span> than its left neighbour, but <span style='color: red;'>BIGGER</span> than its right neighbour!";
  79.             }
  80.             else {
  81.  
  82.                 output = "The number is <span style='color: red;'>SMALLER</span> than its left neighbour and <span style='color: red;'>EQUAL</span> to its right neighbour!";
  83.             }
  84.         }
  85.         if(arr[index] == arr[index - 1]) {
  86.  
  87.             if(arr[index] == arr[index + 1]) {
  88.  
  89.                 output = "The number is <span style='color: red;'>EQUAL</span> to its two neighbours!";
  90.             }
  91.             else if(arr[index] > arr[index + 1]) {
  92.  
  93.                 output = "The number is <span style='color: red;'>EQUAL</span> than its left neighbour, but <span style='color: red;'>BIGGER</span> than its right neighbour!";
  94.             }
  95.             else {
  96.  
  97.                 output = "The number is <span style='color: red;'>EQUAL</span> than its left neighbour and <span style='color: red;'>BIGGER</span> to its right neighbour!";
  98.             }
  99.         }
  100.     }
  101.  
  102.     return output;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment