Last active
February 8, 2017 16:45
-
-
Save raullucero/efe1ac14eb6cd749f2439290dc7b6183 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tax = [[0, 0.1], | |
[1000, 0.2], | |
[4000, 0.3], | |
[6000, 0.4], | |
[6700, 0.6]]; | |
const calcTax = (taxesTable, income) => { | |
let total = 0; | |
let index = taxesTable.findIndex((item) => { | |
return item[0] > income; | |
}); | |
if(index === -1) { | |
index = taxesTable.length; | |
} | |
console.log(index); | |
for(let i = 0; i < index; i++) { | |
if(index === 1) { | |
total = (income * taxesTable[i][1]); | |
console.log(total) | |
} else if(i + 1 === index){ | |
console.log((income - taxesTable[i][0]) * taxesTable[i][1]) | |
total += (income - taxesTable[i][0]) * taxesTable[i][1]; | |
} else { | |
console.log((taxesTable[i + 1][0] - taxesTable[i][0]) * taxesTable[i][1]); | |
total += (taxesTable[i + 1][0] - taxesTable[i][0]) * taxesTable[i][1]; | |
} | |
} | |
console.log(total); | |
console.log('-'.repeat(100)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment