Skip to content

Instantly share code, notes, and snippets.

View bflannery's full-sized avatar
💭
When in doubt, log it out

Brian bflannery

💭
When in doubt, log it out
View GitHub Profile

Keybase proof

I hereby claim:

  • I am bflannery on github.
  • I am bflanneryatx (https://keybase.io/bflanneryatx) on keybase.
  • I have a public key ASCZM5oBZsOAVNP9U1OgIwdKOlCJ08g2peWYNeiuiw1ODwo

To claim this, I am signing this object:

@bflannery
bflannery / sameFrequency.js
Created February 3, 2019 13:09
Frequency Counter Challenge - sameFrequency
// Frequency Counter - sameFrequency
// Write a function called sameFrequency. Given two positive intergers,
// find out if the two numbers have the same frequency of digits.
// Solution Requirements
// - Time Complexity: O(n)
function sameFrequency(int1, int2) {
const int1Arr = Array.from(int1.toString()).map(Number);
@bflannery
bflannery / es6_hash_table.js
Created January 27, 2019 14:38
ES6 Hash Table
class HashTable {
constructor(size) {
this.buckets = Array(size);
this.numBuckets = this.buckets.length;
}
hash() {
var total = 0;
for (var i = 0; i < key.length; i++) {
total += key.charCodeAt(i);
@bflannery
bflannery / binary_search_tree.js
Created January 26, 2019 14:05
ES6 Binary Search Tree
class BST {
constructor(value) {
this.value = value;
this.left = null;
this.right = null;
}
insert(value) {
if (value <= this.value) {
if (!this.left) this.left = new BST(value);
@bflannery
bflannery / es6_linked_list.js
Last active January 24, 2019 19:11
ES6 Linked List
class LinkedList {
constructor() {
this.head = null;
this.tail = null;
}
addToHead(value) {
let newNode = new Node(value, this.head, null);
if (this.head) this.head.prev = newNode;
else this.tail = newNode;
@bflannery
bflannery / stack.js
Created January 23, 2019 13:47
JS Stack
const _items = new WeakMap()
class Stack {
constructor(value) {
_items.set(this, []);
}
push(value) {
_items.get(this).push(value);
}
@bflannery
bflannery / async_currency_converter.js
Created January 18, 2019 20:05
Async Currency Converter
const getExchangeRate = async (from, to) => {
try {
const apiKey = '' // Add unique fixer.io apiKey
const response = await axios.get(`http://data.fixer.io/api/latest?access_key=${apiKey}&format=1`)
const euro = 1 / response.data.rates[from];
const rate = euro * response.data.rates[to];
if (isNaN(rate)) {
throw new Error()
}
@Component({
selector: 'friend-tour',
template: `
<input #newFriend
(keyup.enter)="addFriend(newFriend.value)"
(blur)="addFriend(newFriend.value); newFriend.value='' ">
<button (click)="addFriend(newFriend.value)">Add</button>
<ul><li *ngFor="let friend of friends">{{friends}}</li></ul>
@bflannery
bflannery / sumTwoSmallestNumbers.js
Created January 20, 2017 12:37
return the sum of the two smallest positive integers
// return the sum of the two smallest positive integers
function sumTwoSmallestNumbers(numbers) {
let sorting = numbers.sort((a,b) => {
if(a > b) {
return a;
}
});
return sorting[0] + sorting[1];
@bflannery
bflannery / returnATriangle.js
Created January 20, 2017 12:36
Give 3 integers, will they make a triangle
// Give 3 integers, will they make a triangle
function isTriangle(a,b,c){
if(a+b > c && a+c > b && b+c > a) {
return true;
} else {
return false;
}
}