Do wygrania 90ms.:
Funkcja ma zwracać zdyskontowaną kwotę zgodnie z zadanym data.frame
przez initYearDiscounter()
.
kod:
initYearDiscounter <- function(){
data.frame(year = c(2014:2017),
disc = c(4477/3944,4477/4066,4477/4246,1))
}
discountSalary <- function(salary, year){
n <- length(salary)
result <- numeric(n)
dt <- initYearDiscounter()
for(i in 1:length(salary)){
if (year[i] %in% dt$year){ # TO DO this is poor but no time
result[i] <- round(salary[i] * dt[dt$year == year[i],"disc"])
}else{
result[i] <- salary[i]
}
}
result
}
Przypadek testowy:
test_that("multiple", {
# given:
x <- c(7000, 10000, 10000)
year <- c(2015, 2014, 2017)
# when:
result <- discountSalary(x, year)
# then:
expect_equal(c(7708, 11351, 10000), result)
})