Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <script>
- console.clear();
- function chartArray( arr ){
- const arr2 = arr.slice().sort();
- const arr2Len = arr2.length;
- let output = "\n";
- for( let i = 0; i < arr2Len; i++ ){
- output += "\n" + "|".repeat( Math.round( arr2[i] / 10 ) );
- }
- console.log( output );
- }
- let agents = [];
- const startingAgentCount = 100;
- const maxStartingMoney = 1000;
- const minStartingMoney = 100;
- for( let i = 0; i < startingAgentCount; i++ ){
- agents.push( Math.round( ( Math.random() * ( maxStartingMoney - minStartingMoney ) ) + minStartingMoney ) );
- }
- console.log( 'initial' );
- chartArray(agents);
- const taxSchedule = [-0.20, -0.10, 0.0, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70 ];
- let moneyFrom = [];
- let moneyFromAgent;
- for( let i = 0; i < startingAgentCount; i++ ){
- moneyFromAgent = agents[i] * taxSchedule[ Math.floor( i / 10 ) ];
- moneyFrom.push( moneyFromAgent );
- }
- console.log("agents");
- chartArray(agents);
- console.log("moneyFrom");
- chartArray(moneyFrom);
- let totalMoney = agents.reduce((a, b) => { return a + b; }, 0);
- console.log( 'totalMoney: ' + totalMoney );
- let netTaxes = moneyFrom.reduce((a, b) => { return a + b; }, 0);
- console.log( 'netTaxes: ' + netTaxes );
- console.log( 'averageTaxRate: ' + ( netTaxes / totalMoney ) );
- for( let i = 0; i < startingAgentCount; i++ ){
- agents[i] -= moneyFrom[ i ];
- }
- totalMoney = agents.reduce((a, b) => { return a + b; });
- console.log( 'totalMoney: ' + totalMoney );
- chartArray(agents);
- //10, 20, 30, 50, 50, 60, 70, 80, 90, 100
- </script>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement