DEV Community

Discussion on: Daily Challenge #30 - What is the price?

Collapse
 
choroba profile image
E. Choroba

Perl solution with tests:

#!/usr/bin/perl
use warnings;
use strict;

sub original_price {
    my ($sale_price, $discount) = @_;
    sprintf '%.2f', $sale_price / (1 - $discount / 100)
}

use Test::More tests => 3;

is original_price(75,    25), '100.00';
is original_price(50,    50), '100.00';
is original_price(51.98, 30), '74.26';
Collapse
 
smz_68 profile image
Ardalan

im not so familier with perl but i like it.