Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. var fs = require('fs');
  2.  
  3. fs.readFile('textfile.txt','utf8', (err, data) =>
  4. {
  5. if (err) throw err;
  6. var TempArray = data.split("\r\n")
  7. var LineCounter = 0;
  8. var IncreaseCounter = 0;
  9. var LastIncrease = 0;
  10. var Invested = false;
  11.  
  12. //Count through values in the textfile
  13. for(var i = 0;i < TempArray.length;i++)
  14. {
  15. LineCounter++;
  16. if(TempArray[i] > TempArray[i-1] && !Invested)
  17. {
  18. if(IncreaseCounter > 0 && LastIncrease == LineCounter - 1)+
  19. {
  20. IncreaseCounter++
  21. }
  22. else if(IncreaseCounter == 0)
  23. {
  24. IncreaseCounter++
  25. }
  26. else
  27. {
  28. IncreaseCounter == 0;
  29. }
  30. LastIncrease = LineCounter;
  31. if(IncreaseCounter == 3)
  32. {
  33. console.log("Purchase ducats on line ", LineCounter)
  34. Invested = true;
  35. IncreaseCounter = 0;
  36. }
  37. }
  38. if(Invested)
  39. {
  40. if(TempArray[i] < TempArray[i-1])
  41. {
  42. console.log("Sell ducats on line ", LineCounter);
  43. Invested = false;
  44. }
  45. }
  46. }
  47. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement