Skip to content

Instantly share code, notes, and snippets.

@codingwithrachel
codingwithrachel / human.js
Created September 17, 2023 17:55
Class-based inheritance ES6
class Human {
constructor (firstName, lastName) {
this.firstName = firstName
this.lastName = lastName
}
}
let human1 = new Human("rachel", "green")
let human2 = new Human("ross", "geller")
package.json
```
...
"moduleRoots": [
"",
"custom-resolver.js"
],
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.3.0",
"@babel/plugin-syntax-jsx": "^7.2.0",
/*
Depth-first search
a
/ \
b c
/|\ \
d e f g
|
h
@codingwithrachel
codingwithrachel / perform_raindrop.js
Last active December 7, 2018 21:44
Authenticating with Hydro Raindrop Contract via web3
async function sendSignedTransaction(web3, privateKey, nonce, gasPrice, gasLimit, to, from, data) {
try {
const rawTx1 = {
nonce: nonce,
gasPrice: gasPrice,
gasLimit: gasLimit,
to: to,
from: from,
data: data
@codingwithrachel
codingwithrachel / rps.js
Created September 25, 2018 15:07
create combinations of rock paper scissors
function rps(rounds) {
var obj = {}
var feed = ['r','p','s'];
function recurse(combo, numRoundsLeft) {
if(!numRoundsLeft) {
obj[combo] = 1
return
}
@codingwithrachel
codingwithrachel / anagram.js
Created September 25, 2018 14:49
create anagrams
function anagram(str) {
var obj = {}
function recurse(combo, feed) {
if(!feed.length) {
obj[combo] = 1
return
} else {
for(var i=0; i < feed.length; i++) {
recurse(combo+feed[i], feed.slice(0,i) + feed.slice(i+1))
}
@codingwithrachel
codingwithrachel / mergeIntervals.js
Created September 5, 2018 16:32
Merge meeting intervals
function mergeIntervals(intervals) {
if(intervals.length < 2) return intervals
intervals = intervals.sort(function(a,b) {
return a[0] - b[0]
})
var stack = []
stack.push(intervals[0])
var top
for(var i = 1; i < intervals.length; i++) {
top = stack[stack.length - 1]
@codingwithrachel
codingwithrachel / count.js
Created September 5, 2018 15:17
Count number of words in a string in what line
function count(file) {
var lines = file.split("\n")
var wordToCounterMap = {}
var wordToLineMap = {}
for(var k = 0; k < lines.length; k++) {
countWords(lines[k].split(" "), k)
}
function countWords(words, lineNumber) {
@codingwithrachel
codingwithrachel / regex.js
Last active November 30, 2018 15:26
regex
//detect pangram (has all alphabet characters)
function isPangram(string){
var alphabets = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"
var a = alphabets.split(",")
string = string.replace(/[^a-zA-Z0-9]+/g,"").toLowerCase()
for(var i=0;i<a.length;i++) {
if(string.indexOf(a[i]) === -1) return false;
}
return true;
}
@codingwithrachel
codingwithrachel / codewars.js
Last active November 30, 2018 15:26
codewars
//find count of most frequent item in array
function mostFrequentItemCount(store) {
var frequency = {}
var max = 0;
var result;
for (var v in store) {
frequency[store[v]] = (frequency[store[v]] || 0)+1;
if(frequency[store[v]] > max) {
max = frequency[store[v]];
// result = store[v];