Skip to content

Instantly share code, notes, and snippets.

View dons20's full-sized avatar
💭
Coding

Keno Clayton dons20

💭
Coding
View GitHub Profile
@dons20
dons20 / 0_reuse_code.js
Created December 8, 2016 06:06
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@dons20
dons20 / SampleFlatten.js
Last active December 6, 2018 17:46
This code will flatten an array of arbitrarily nested arrays of integers into a flat array of integers
//e.g. [[1,2,[3]],4] -> [1,2,3,4]
let complexArray = [[1,2,[3]],4];
//Legacy Approach
function flatten(arr) {
return arr.reduce(function (flat, toFlatten) {
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
}
sampleInput1 = ("5 1\n"
"0 2 3\n"
"1 3 0\n"
"2 3 0\n"
"3 2 1\n"
"4 6 5\n"
)
def assign(orders):
@dons20
dons20 / table.js
Last active November 2, 2020 20:55
Prints out the multiplication table up to 12x12
// Create array of 12 items from 1-12
let values = Array.from({length: 12}, (_, i) => i + 1);
// Iterate through array (new console log for each line)
values.forEach(value => console.log(Array.from({length: 12}, (_, i) => (i+1) * value).join(" ")));
// Alternative if one console log is to be displayed.
let table = [];
table = values.map(value => Array.from({length: 12}, (_, i) => (i+1) * value).join("\t\t"));
console.log(table.join("\n"));