Last active
March 22, 2018 21:41
-
-
Save jdeisenberg/fc954308e1c794b4a20c8bae116f2e4f to your computer and use it in GitHub Desktop.
Test of lists vs. JSON in reason
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
[@bs.module] external lab : Js.t({..}) = "./lab.json"; | |
let components = lab##components; | |
let length = list => { | |
let rec addUpLength = (innerList, currentTotal) => | |
switch (innerList) { | |
| [] => currentTotal | |
| [head, ...tail] => {Js.log(head); Js.log("****"); addUpLength(tail, currentTotal + 1)} | |
}; | |
addUpLength(list, 0); | |
}; | |
/* Test that length() works on a standard list */ | |
Js.log(length([11,22,33,44,55])); | |
Js.log("------------------------------"); | |
Js.log2("Use array slice: ", Js.Array.slice(~start=2, ~end_=3, components)); | |
Js.log2("Use Belt array get: ", Belt.Array.get(components, 2)); | |
Js.log2("Use Belt list get: ", Belt.List.get(components, 2)); | |
Js.log("======================"); | |
Js.log2("length using recursive function: ", length(components)); | |
Js.log2("length using array length: ", Belt.Array.length(components)); | |
Js.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); | |
let third = components[2]; | |
Js.log2("THIRD", third); | |
let fourth = components[3]; | |
Js.log2("FOURTH", fourth); | |
/* This goes into lab.json | |
{ | |
"name": "blah", | |
"components": [ | |
{ "name": "David", "age": 64}, | |
{ "name": "Nancy", "age": 35}, | |
{ "name": "Fred", "age": 22}, | |
{ "name": "Michele", "age": 40} | |
] | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment