Fix the Scala Method
Fix the missing semicolons and the Int type, ensure the floating point division, and remove the unnecessary return.
Start file
def calculateTotalPrice(items List[Double], discountPercentage int): Double = {
val subtotal = items.sum
val discountAmount = subtotal * (discountPercentage / 100)
val total = subtotal - discountAmount
return total
}
End file
def calculateTotalPrice(items: List[Double], discountPercentage: Int): Double = {
val subtotal = items.sum
val discountAmount = subtotal * (discountPercentage / 100.0)
val total = subtotal - discountAmount
total
}
View Diff
1c1
< def calculateTotalPrice(items List[Double], discountPercentage int): Double = {
---
> def calculateTotalPrice(items: List[Double], discountPercentage: Int): Double = {
3c3
< val discountAmount = subtotal * (discountPercentage / 100)
---
> val discountAmount = subtotal * (discountPercentage / 100.0)
5c5
< return total
---
> total
Solutions
The best way to learn is to practice. Below, you will find some of the solutions other golfers have entered. To unlock higher ranked solutions, submit your own entry which does as well or better than the solutions you can currently see - climb the ladder!
Check out these helpful resources to improve your Vim skills... Game on.
Unlock 56 remaining solutions by signing in and submitting your own entry
#57 colorless green idea / @dkrentzlin - Score: 43 - 11/22/24 @ 10:31
/s<CR>a:<Esc>/gea<BS><CR>al<BS><Esc>la:<Esc>llrI<Esc>/10<CR>wi.0<Esc>/r<CR>dw:wq<CR>
0 comments