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
/*** | |
Suppose we have some input data describing a graph of relationships between parents and children over multiple generations. The data is formatted as a list of (parent, child) pairs, where each individual is assigned a unique integer identifier. | |
For example, in this diagram, 3 is a child of 1 and 2, and 5 is a child of 4: | |
1 2 4 | |
\ / / \ | |
3 5 8 | |
\ / \ \ | |
6 7 9 |
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
function getDecentNumber(N) { | |
let number = -1, | |
inc = 5, | |
five_str = "5", | |
three_str = "3", | |
five_num = 5, | |
three_num = 3; | |
// numberCast function will turn any string up to 16 digits |
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
const throwIfMissing = (p) => { throw new Error(`Missing parameter: ${p}`); } | |
function famTree(dad = throwIfMissing("dad"),mom = throwIfMissing("mom"),...siblings) { | |
console.group("Family"); | |
console.log(`Dad: ${dad}`); | |
console.log(`Mom: ${mom}`); | |
if(siblings.length > 0) { | |
console.log(`Siblings: ${siblings.join()}`); | |
} | |
console.groupEnd(); |
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
// Caculate sum of numbers in nested array | |
//----------------------------------------// | |
const arrSet = [[1,2,3],4,5,"h","e",["l","o", null, false, true], 3.75, -1]; | |
const FlattenArray = function(arr) { | |
return arr.reduce((a,c) => { | |
return Array.isArray(c) ? a.concat(FlattenArray(c)) : a.concat(c); | |
}, []); | |
} | |
const FlattenArrayByString = function(arr) { |
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
class List extends Array { | |
constructor() { | |
super(...arguments); | |
} | |
uniq() { | |
return [... new Set(this)]; | |
} | |
empty() { |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Elton ui Kit</title> | |
<style> | |
@import 'https://fonts.googleapis.com/css?family=Comfortaa:300,700|Bungee+Shade|Josefin+Sans:400'; | |
html { | |
background-color: #eee; |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>AutoTab</title> | |
<style> | |
body { | |
min-height: 100vh; | |
display: flex; | |
justify-content: center; |
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
{ | |
"User snippet": { | |
"scope": "json", | |
"prefix": "u-snp", | |
"body": [ | |
"\"${1:snippet_name}\": {", | |
"\t\"prefix\": \"${2:snippet_prefix}\",", | |
"\t\"body\": [", | |
"\t\t$3", | |
"\t],", |
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
/** | |
* Couple of possible solutions to the Sock Merchant challenge on Hacker Rank | |
* https://www.hackerrank.com/challenges/sock-merchant/problem | |
**/ | |
// Solution 1 | |
// Video tutorial can be viewed: https://youtu.be/DRp6naqL5uc | |
function sortAndCount( n, arr ) { | |
let sorted = arr.sort( (a,b) => a - b); | |
let pairs = 0; |
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
if(!Array.prototype.uniq) { | |
Array.prototype.uniq = function() { | |
return this.reduce( (arr, val) => { | |
if (!arr.includes(val)) arr.push(val); | |
return arr; | |
}, [] ) | |
} | |
} |