Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function checkIfBigger(n, array) {
- var index = parseInt(n);
- var arrParsed = parseArr(array);
- var arr = arrParsed.split(",");
- var output = "";
- if(index == 0) {
- if(arr.length != 1) {
- if(parseInt(arr[index]) > parseInt(arr[index + 1])) {
- output = "No left neighbour, but <span style='color: red;'>BIGGER</span> than the right neighbour!";
- }
- else if(parseInt(arr[index]) == parseInt(arr[index + 1])) {
- output = "No left neighbour and <span style='color: red;'>EQUAL</span> to the right neighbour!";
- }
- else {
- output = "No left neighbour and <span style='color: red;'>SMALLER</span> than the right neighbour!";
- }
- }
- else {
- output = "No neighbours!";
- }
- }
- else if(index == (arr.length - 1)) {
- if(arr.length != 1) {
- if(parseInt(arr[index]) > parseInt(arr[index - 1])) {
- output = "No right neighbour, but <span style='color: red;'>BIGGER</span> than the left neighbour!";
- }
- else if(parseInt(arr[index]) == parseInt(arr[index - 1])) {
- output = "No right neighbour and <span style='color: red;'>EQUAL</span> to the left neighbour!";
- }
- else {
- output = "No right neighbour and <span style='color: red;'>SMALLER</span> than the left neighbour!";
- }
- }
- else {
- output = "No neighbours!";
- }
- }
- else if(index > 0 && index < (arr.length - 1)) {
- if(arr[index] > arr[index - 1]) {
- if(arr[index] > arr[index + 1]) {
- output = "The number is <span style='color: red;'>BIGGER</span> than its two neighbours!";
- }
- else if(arr[index] < arr[index + 1]) {
- 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!";
- }
- else {
- 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!";
- }
- }
- if(arr[index] < arr[index - 1]) {
- if(arr[index] < arr[index + 1]) {
- output = "The number is <span style='color: red;'>SMALLER</span> than its two neighbours!";
- }
- else if(arr[index] > arr[index + 1]) {
- 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!";
- }
- else {
- 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!";
- }
- }
- if(arr[index] == arr[index - 1]) {
- if(arr[index] == arr[index + 1]) {
- output = "The number is <span style='color: red;'>EQUAL</span> to its two neighbours!";
- }
- else if(arr[index] > arr[index + 1]) {
- 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!";
- }
- else {
- 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!";
- }
- }
- }
- return output;
- }
Advertisement
Add Comment
Please, Sign In to add comment