Advertisement
VoidRayChe

NEXUS

Jan 27th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. function nexus(input){
  2. let arrayOne = input.shift().split(' ');
  3. let arrayTwo = input.shift().split(' ');
  4. nexusArr = input;
  5. let nexusStr = 'notNexus';
  6.  
  7.  
  8. while(nexusStr != 'nexus'){
  9. nexusStr = nexusArr.shift();
  10. if(nexusStr != 'nexus'){
  11. let arr = nexusStr.split(/(\d+):(\d+)\|(\d+):(\d+)/);
  12. let arrayOneBegin = +arr[1], arrayTwoEnd = +arr[2], arrayTwoBegin = +arr[4], arrayOneEnd = +arr[3];
  13. let crossing = false;
  14.  
  15. if(isBetween(arrayOneBegin, arrayTwoBegin, arrayOneEnd) || isBetween(arrayTwoEnd, arrayTwoBegin, arrayOneEnd)
  16. || isBetween(arrayTwoBegin, arrayOneBegin, arrayTwoEnd) || isBetween(arrayOneEnd, arrayOneBegin, arrayTwoEnd))
  17. crossing = true;
  18.  
  19. if(crossing == true){
  20. let nexusValue = +arrayOne[arrayOneBegin] + +arrayOne[arrayOneEnd] + +arrayTwo[arrayTwoBegin] + +arrayTwo[arrayTwoEnd];
  21. arrayOne.splice(arrayOneBegin, arrayOneEnd-arrayOneBegin+1);
  22. arrayTwo.splice(arrayTwoBegin, arrayTwoEnd-arrayTwoBegin+1);
  23. addNexusValue(arrayOne, nexusValue);
  24. addNexusValue(arrayTwo, nexusValue);
  25. }
  26. crossing = false;
  27. }
  28. else{
  29. print(arrayOne);
  30. print(arrayTwo);
  31. }
  32. }
  33.  
  34. function print(arr){
  35. let strLine = "";
  36. arr.forEach(el => strLine = strLine + ((strLine!="")?", ":"") + el );
  37. console.log(strLine);
  38. }
  39. function addNexusValue(arr, nexusValue){
  40. for(let i = 0; i < arr.length; i++)
  41. arr[i] = +(arr[i]) + nexusValue;
  42. }
  43.  
  44. function isBetween(el, from, to){
  45. if(el >= from && el <= to)
  46. return true;
  47. return false;
  48. }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement