Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let currentNum = 0;
  2. let storedNum = 0;
  3.  
  4. let history = [];
  5. let historyIndex = null;
  6.  
  7. function addHistory() {
  8.   let historyObject = {lastNum: currentNum,
  9.                        value: storedNum};
  10.   history.unshift(historyObject);
  11.   historyIndex = null;
  12.  
  13. function historyBack() {
  14.   if (historyIndex === history.length - 1) {
  15.     return;
  16.   }
  17.   if (historyIndex === null) {
  18.     historyIndex = 0;
  19.   } else {
  20.     historyIndex++;
  21.   }
  22.   setHistoryValues();
  23. }
  24.  
  25. function setHistoryValues() {
  26.   let historyObject = history[historyIndex];
  27.   currentNum = historyObject.lastNum;
  28.   storedNum = historyObject.value;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement