Calculating the salary based on salary – JS
In this calculation, which logs
{ level: 20, salary: 549884 }
, how can you get the amount from salary, 549884 and times it with 38,6%?
Basically: salary * 1,368 ...
To be clear: how do I draw out the salary amount to use in further
calculations ...6 Replies
think it would be easier to use a lookup tabel. here an array of objects with the active years, the level and salary.
based on the "yearsSince" you can find the row that matches and destruct the level and salary from it
Damn! This is where I started this morning, but I never figured out the array set up and how to extract the salary. This makes sense in terms of set up, but could you explain what happens in this part
yearsSince >= row.years[0] && yearsSince < row.years[1]
?
The way I understand it is that you find the row (salaryScale.find ...
) based on the indeces of the year array. Is this correct ...? So: 2014 gives a value of 9, and 9 falls in between [8, 10]
..find()
is an array method. Almost the same as filter()
but it will only give the first match
and indeed the logic is actually the same as you did before.Right, and instead of creating two let variables of level and salary and running if statements on them, you're running the .find() and "populating" level and salary with the values from the first row that matches the indeces of years.
Or ... @MarkBoots ?
😅
To answer your original question, which wasn't about how to optimize your code, you can do something like this:
Ah. So simply creating a variable ... jeez. I was lost inside of the calculations, and never really thought of that. 🥴