Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Study</title>
- </head>
- <body>
- <script>
- `use strict`
- function printFract(fract, printer = (str) => console.log(str)) {
- printer(`(${fract.num}/${fract.denom})`);
- }
- function mulFract(fractA, fractB) {
- return reduce({ num: (fractA.num * fractB.num), denom: (fractA.denom * fractB.denom)});
- }
- function reduce(fract) {
- // reduce code goes here
- let gcdVal = gcd(fract);
- fract.num /= gcdVal
- fract.denom /= gcdVal;
- return fract;
- }
- {
- let frac1 = { num: 1, denom: 3 };
- let frac2 = { num: 1, denom: 2 };
- let frac3 = { num: 1, denom: 4 };
- //(2 * 3) * 4
- printFract(frac1);
- printFract(frac2);
- printFract(mulFract(frac1, frac2));
- console.log(mulFract(mulFract(frac1, frac2), frac3));
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement