Skip to content

Instantly share code, notes, and snippets.

View jcar787's full-sized avatar

Jeff C. jcar787

View GitHub Profile
@jcar787
jcar787 / DequeTest.java
Created September 27, 2014 20:52
Unittest for the Deque class
import java.util.Iterator;
import java.util.NoSuchElementException;
import junit.framework.TestCase;
public class DequeTest extends TestCase {
Deque<Integer> deque;
protected void setUp() throws Exception {
super.setUp();
deque = new Deque<Integer>();
@jcar787
jcar787 / RandomizedQueueTest.java
Created September 27, 2014 23:42
Unittest for the RandomizedQueue class
import java.util.Iterator;
import java.util.NoSuchElementException;
import junit.framework.TestCase;
public class RandomizedQueueTest extends TestCase {
RandomizedQueue<Integer> ran;
public void setUp() throws Exception {
super.setUp();
ran = new RandomizedQueue<Integer>();
@jcar787
jcar787 / ex4.js
Created April 11, 2019 04:30
Exercise 4
function lotteryNum() {
return (Math.round(Math.random() * 100) % 58) + 1;
}
function pickNumber(numbers) {
let newNumber;
let found;
do {
newNumber = lotteryNum();
found = numbers.find(number => newNumber === number);
const numJewelsInStones = (jewels, stones) => {
const cache = {};
for (const j of jewels) {
cache[j] = 0
}
for (const s of stones) {
if (s in cache) {
cache[s]++;
# code --list-extensions | xargs -L 1 echo code --install-extension
code --install-extension asvetliakov.snapshot-tools
code --install-extension burkeholland.simple-react-snippets
code --install-extension CoenraadS.bracket-pair-colorizer
code --install-extension dbaeumer.vscode-eslint
code --install-extension donjayamanne.githistory
code --install-extension eamodio.gitlens
code --install-extension esbenp.prettier-vscode
code --install-extension liximomo.sftp
code --install-extension mermade.openapi-lint
@jcar787
jcar787 / heap.js
Created May 30, 2021 02:26
Implementation of MinHeap and MaxHeap in JavaScript
const createMinHeap = () => {
const items = [];
const percolateUp = index => {
const parent = Math.floor((index - 1) / 2);
if (index > 0 && items[parent] > items[index]) {
[items[parent], items[index]] = [items[index], items[parent]];
percolateUp(parent);
}
@jcar787
jcar787 / map-example.js
Created February 26, 2022 08:59
An example of map
const chars = [ 'j','a','v','a','s','c','r','i','p','t' ];
const ascii = chars.map(chr => chr.charCodeAt(0));
@jcar787
jcar787 / filter-example.js
Created February 26, 2022 09:08
A filter example
const chars = [ 'j','a','v','a','s','c','r','i','p','t' ];
const justAs = chars.filter(chr => chr === 'a');
@jcar787
jcar787 / trivial-reduce.js
Created February 26, 2022 09:14
Trivial reduce example
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const total = numbers.reduce((sum, number) => sum + number);
@jcar787
jcar787 / trivial-but-better-reduce.js
Created February 26, 2022 09:21
Trivial reduce example but better
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const total = numbers.reduce((sum, number) => {
const currentTotal = sum + number;
return currentTotal;
}, 0);