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
| // simple function to convert csv string with header to json string | |
| function csv_to_json(csv_string, splitter = ','){ | |
| const lines = csv_string.split("\n"); | |
| const headers = lines[0].split(splitter); | |
| const result = lines.map( line => { | |
| let obj = {}; | |
| const data_items = line.split(splitter); | |
| headers.forEach( (header, i) => { | |
| obj[header] = data_items[i]; | |
| }); |
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
| // https://en.wikipedia.org/wiki/Collatz_conjecture | |
| function collatzStep(n: number): number { | |
| if (n % 2 === 0) { | |
| return n/2; | |
| } else { | |
| return (n * 3) + 1; | |
| } | |
| } | |
| let i: number = 1; |
OlderNewer