DEV Community

Daily Challenge #138 - Do I get a Bonus?

dev.to staff on December 16, 2019

It's bonus time in the big city! The fatcats are rubbing their paws in anticipation... but who is going to make the most money? Build a function t...
Collapse
 
nickholmesde profile image
Nick Holmes

Here's an F# version of the function without obvious args, and really without any multiplication;

let payDay = function | true -> sprintf "€%d0" | _ -> sprintf "€%d"

But it works...

let pay = payDay true 100
// pay = "€1000"
Collapse
 
erezwanderman profile image
erezwanderman

QBasic!

DECLARE FUNCTION CALC$ (salary!, bonus!)
CONST False = 0
CONST True = 1
CLS
PRINT CALC(32, True)
PRINT CALC(32, False)

FUNCTION CALC$(salary, bonus)
    CALC$ = "$" + LTRIM$(STR$(salary * (bonus * 9 + 1)))
END FUNCTION
Collapse
 
yechielk profile image
Yechiel Kalmenson • Edited

Ruby:

def total_salary(base_salary, getting_bonus)
    "$#{getting_bonus ? (base_salary * 10).to_s : base_salary.to_s}"
end
Collapse
 
yechielk profile image
Yechiel Kalmenson

lol, haven't used Ruby in a while so I wanted to be sure (though, now that you mention it, implicitly converting to string in interpolation makes sense :)

Clever on adding a zero!

Collapse
 
nickyoung profile image
Nick Young • Edited

Untested PHP attempt:

function get_salary( $salary, $bonus )  {
    return '$' . ( $bonus ? $salary * 10 : $salary );
}
Collapse
 
rehmatfalcon profile image
Kushal Niroula

JS Quick and dirty :)

function salary(salary, bonus) {
    return ${bonus? salary * 10 : salary}`;
}
Collapse
 
vaibhavyadav1998 profile image
Vaibhav Yadav

In Go.


import "fmt"

func finalSalary(salary int, bonus bool) string {
    if bonus {
        return fmt.Sprintf("\u00A3 %d", salary*10)
    }
    return fmt.Sprintf("\u00A3 %d", salary)
}
Collapse
 
raucoustortoise profile image
Michael Mather

Python:

def get_salary(salary, bonus):
    return f'${salary * 10**bonus}'
Collapse
 
nickholmesde profile image
Nick Holmes

Obtuse, but fun!

Collapse
 
nickholmesde profile image
Nick Holmes

Clearly, F# doesn't pay well enough.