Advertisement
Guest User

Untitled

a guest
Jun 13th, 2020
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. const getGets = (arr) => {
  2. let index = 0;
  3.  
  4. return () => {
  5. const toReturn = arr[index];
  6. index += 1;
  7. return toReturn;
  8. };
  9. };
  10. // this is the test
  11. const test = [
  12. 6, -26, -25, -28, 31, 2, 27
  13. ];
  14.  
  15.  
  16. const gets = this.gets || getGets(test);
  17. const print = this.print || console.log;
  18.  
  19. // code
  20.  
  21.  
  22. const n = +gets();
  23. const arr = new Array();
  24.  
  25. for(let i = 0; i < n; i++) {
  26. arr.push(gets());
  27. }
  28.  
  29. var result = -1;
  30.  
  31. for (var index = 0; index < arr.length - 1; index++) {
  32. if((index == 0) || (index == arr.length - 1)){
  33. continue;
  34. }else{
  35. if ((arr[index - 1] < arr[index]) && (arr[index] > arr[index + 1])){
  36. result = index;
  37. break;
  38. }
  39. }
  40. }
  41. print(result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement