Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var fs = require('fs');
- fs.readFile('textfile.txt','utf8', (err, data) =>
- {
- if (err) throw err;
- var TempArray = data.split("\r\n")
- var LineCounter = 0;
- var IncreaseCounter = 0;
- var LastIncrease = 0;
- var Invested = false;
- //Count through values in the textfile
- for(var i = 0;i < TempArray.length;i++)
- {
- LineCounter++;
- if(TempArray[i] > TempArray[i-1] && !Invested)
- {
- if(IncreaseCounter > 0 && LastIncrease == LineCounter - 1)+
- {
- IncreaseCounter++
- }
- else if(IncreaseCounter == 0)
- {
- IncreaseCounter++
- }
- else
- {
- IncreaseCounter == 0;
- }
- LastIncrease = LineCounter;
- if(IncreaseCounter == 3)
- {
- console.log("Purchase ducats on line ", LineCounter)
- Invested = true;
- IncreaseCounter = 0;
- }
- }
- if(Invested)
- {
- if(TempArray[i] < TempArray[i-1])
- {
- console.log("Sell ducats on line ", LineCounter);
- Invested = false;
- }
- }
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement