Created
February 10, 2020 09:28
-
-
Save IwanKaramazow/765493b5677a56e8df38cb7e35afda70 to your computer and use it in GitHub Desktop.
missing.ns
This file contains 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
open BinarySearchTree | |
module List = Belt.List | |
let rec weave = (list1, list2, prefix, results) => | |
switch (list1, list2) { | |
| (list[], _) | (_, list[]) => | |
let everything = List.concatMany([prefix, list1, list2])->List.toArray | |
results->Js.Array2.push(everything)->ignore | |
| (list[hd1, ...tail1], list[hd2, ...tail2]) => | |
let oldPrefix = prefix | |
let newPrefix = oldPrefix->List.add(hd1) | |
weave(tail1, tail2, newPrefix, results) | |
let newPrefix = oldPrefix->List.add(hd2) | |
weave(tail1, tail2, newPrefix, results) | |
() | |
} | |
let () = { | |
let results = [] | |
weave(list[1, 2], list[3, 4], []) | |
Js.log(results) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment