Skip to content

Instantly share code, notes, and snippets.

View wertlex's full-sized avatar
🙈
Balance

Alex V. Povar wertlex

🙈
Balance
View GitHub Profile
// 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];
});
// 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;