Skip to content

Instantly share code, notes, and snippets.

@drewwells
Created September 25, 2011 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drewwells/1240652 to your computer and use it in GitHub Desktop.
Save drewwells/1240652 to your computer and use it in GitHub Desktop.
var i,l,death,
taxes = [
{
value: 0,
rate: .1
},
{
value: 5070,
rate: .14
},
{
value: 8660,
rate: .23
},
{
value: 14070,
rate: .30
},
{
value: 21240,
rate: .33
},
{
value: 40230,
rate: .45
}
];
//Copy of args
var args = process.argv.slice( 2 ), result = [];
for( i = 0, l = args.length; death = taxes.length, i < l; i ++ ){
args[ i ] = parseInt( args[ i ], 10 );
result[ i ] = 0;
while( death-- > 0 ){
if( args[ i ] > taxes[ death ].value ){
result[ i ] += ( args[ i ] - taxes[ death ].value )
* taxes[ death ].rate;
args[ i ] -= ( args[ i ] - taxes[ death ].value );
}
}
result[ i ] = Math.round( result[ i ] * 100 ) / 100;
console.log( process.argv[ i + 2 ],
'->', result[ i ] );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment