This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const getDigits = str => str.split("").map(digit => parseInt(digit, 10)); | |
| const stripZeros = digits => | |
| digits.length <= 1 ? digits : digits.replace(/^0*/, ""); | |
| const _addBignums = (num1, num2) => { | |
| const digits1 = getDigits(num1).reverse(); // [3, 2, 2] | |
| const digits2 = getDigits(num2).reverse(); // [4, 1] | |
| let carry = 0; // Me dice si debo agregar un carry en esta iteraci贸n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module FizzBuzz where | |
| import Data.Foldable (traverse_) | |
| divisibleBy :: Int -> Int -> Bool | |
| divisibleBy divisor x = x `mod` divisor == 0 | |
| data FizzResult v pt pf rt rf | |
| = Val v pf rf | |
| | Fizz pt rf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- We don't really care about the types pt, pf, rt and rf here, | |
| -- and we want to get an Int back when both predicates are false. | |
| type FizzBuzz = FizzResult Int () () () () | |
| -- Helper function to format predicates to the form mkFizzBuzz needs. | |
| boolToEither :: Bool -> Either () () | |
| boolToEither True = Right () | |
| boolToEither False = Left () | |
| fizzbuzz :: Int -> FizzBuzz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mkFizzBuzz :: (v -> Either pf pt) -> (v -> Either rf rt) -> v -> FizzResult v pt pf rt rf | |
| mkFizzBuzz p1 p2 v = | |
| case (p1 v, p2 v) of | |
| (Right pt, Right rt) -> FizzBuzz pt rt | |
| (Right pt, Left rf) -> Fizz pt rf | |
| (Left pf, Right rt) -> Buzz pf rt | |
| (Left pf, Left rf) -> Val v pf rf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data FizzResult v pt pf rt rf | |
| = Val v pf rf | |
| | Fizz pt rf | |
| | Buzz pf rt | |
| | FizzBuzz pt rt | |
| deriving (Show) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data FizzResult a | |
| = Val a | |
| | Fizz | |
| | Buzz | |
| | FizzBuzz | |
| deriving (Show) | |
| mkFizzBuzz :: (a -> Bool) -> (a -> Bool) -> a -> FizzResult a | |
| mkFizzBuzz p r a = | |
| case (p a, r a) of |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module FizzBuzz where | |
| data FizzResult | |
| = Val Int | |
| | Fizz | |
| | Buzz | |
| | FizzBuzz | |
| deriving (Show) | |
| divisibleBy :: Int -> Int -> Bool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jsCall : String -> a | |
| jsCall funcName = | |
| jsCall funcName |