Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. <html>
  2. <script>
  3. console.clear();
  4. function chartArray( arr ){
  5. const arr2 = arr.slice().sort();
  6. const arr2Len = arr2.length;
  7. let output = "\n";
  8. for( let i = 0; i < arr2Len; i++ ){
  9. output += "\n" + "|".repeat( Math.round( arr2[i] / 10 ) );
  10. }
  11. console.log( output );
  12. }
  13.  
  14. let agents = [];
  15. const startingAgentCount = 100;
  16. const maxStartingMoney = 1000;
  17. const minStartingMoney = 100;
  18. for( let i = 0; i < startingAgentCount; i++ ){
  19. agents.push( Math.round( ( Math.random() * ( maxStartingMoney - minStartingMoney ) ) + minStartingMoney ) );
  20. }
  21. console.log( 'initial' );
  22. chartArray(agents);
  23.  
  24.  
  25. const taxSchedule = [-0.20, -0.10, 0.0, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70 ];
  26. let moneyFrom = [];
  27.  
  28. let moneyFromAgent;
  29. for( let i = 0; i < startingAgentCount; i++ ){
  30. moneyFromAgent = agents[i] * taxSchedule[ Math.floor( i / 10 ) ];
  31. moneyFrom.push( moneyFromAgent );
  32. }
  33. console.log("agents");
  34. chartArray(agents);
  35. console.log("moneyFrom");
  36. chartArray(moneyFrom);
  37.  
  38. let totalMoney = agents.reduce((a, b) => { return a + b; }, 0);
  39. console.log( 'totalMoney: ' + totalMoney );
  40. let netTaxes = moneyFrom.reduce((a, b) => { return a + b; }, 0);
  41. console.log( 'netTaxes: ' + netTaxes );
  42. console.log( 'averageTaxRate: ' + ( netTaxes / totalMoney ) );
  43.  
  44. for( let i = 0; i < startingAgentCount; i++ ){
  45. agents[i] -= moneyFrom[ i ];
  46. }
  47.  
  48. totalMoney = agents.reduce((a, b) => { return a + b; });
  49. console.log( 'totalMoney: ' + totalMoney );
  50.  
  51. chartArray(agents);
  52.  
  53.  
  54. //10, 20, 30, 50, 50, 60, 70, 80, 90, 100
  55. </script>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement