This is a list of my solutions for Functional Programming Challenge in hackerrank and solved with OCaml.
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
| # ini membutuhkan direnv | |
| # maka install juga direnv | |
| # agar .envrc dapat dijalankan | |
| # isi dari .envrc adalah | |
| use nix |
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
| window: | |
| dimensions: | |
| columns: 0 | |
| lines: 0 | |
| padding: | |
| x: 0 | |
| y: 0 | |
| dynamic_padding: false |
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
| use flake |
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 write Maybe module (stolen from haskell) | |
| module Maybe = { | |
| type t<'a> = | |
| | Just('a) | |
| | Nothing | |
| let fmap = (x, fn) => | |
| switch x { | |
| | Just(x) => Just(x->fn) | |
| | Nothing => Nothing |
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 add = (a, b) => a + b | |
| const adds = (...n) => n.reduce(add) | |
| const mul = (a, b) => a * b | |
| const muls = (...n) => n.reduce(mul) | |
| const div = (a, b) => a / b | |
| const divs = (...n) => n.reduce(div) | |
| const mod = (a, b) => a % b |
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
| /** | |
| * @param {Number} n | |
| * @return {Number} | |
| * @example | |
| * | |
| * reverseNumber(123) // 321 | |
| * reverseNumber(212) // 212 | |
| * reverseNumber(123456789) // 987654321 | |
| */ | |
| const reverseNumber = (input) => { |
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
| use nix |
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
| // HEY TAYO HEY TAYO DIA SI FUNGSI NAKAL MELAJU MENGHAJAR | |
| // basic operation {a + b} {a - b} as function | |
| let add = (a, b) => a + b; | |
| let sub = (a, b) => a - b; | |
| // function for add one {a + 1} | |
| let addOne = (b) => add(1, b); | |
| // function for reverse value by length that defined as {a} | |
| // and solve with Math | |
| let reverse = (a, b) => addOne(sub(a, b)); | |
| // function for know the maximum value of numbers |