Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Gerst Gerst20051

View GitHub Profile
View groupAnagrams.js
function groupAnagrams(listOfStrings) {
return listOfStrings.reduce((groups, string) => {
for (let i = 0; i < groups.length; i++) {
if (isAnagram(groups[i][0], string)) {
groups[i].push(string);
return groups;
}
}
groups.push([string]);
return groups;
@Gerst20051
Gerst20051 / findFirstUniqueCharacterInString.js
Created Oct 15, 2020
Find First Unique Character In String
View findFirstUniqueCharacterInString.js
function findUniqueCharacter(string) {
const characterMap = buildCharacterMap(string);
return findFirstUniqueCharacterInMap(characterMap);
}
function buildCharacterMap(string) {
return string.split('').reduce((map, character) => {
if (!map[character]) {
map[character] = 1;
} else {
@Gerst20051
Gerst20051 / Calculator.js
Created Oct 1, 2020
Simple Calculator Class
View Calculator.js
class Calculator {
#numbers = {
'zero': 0,
'one': 1,
'two': 2,
'three': 3,
'four': 4,
'five': 5,
'six': 6,
'seven': 7,
@Gerst20051
Gerst20051 / order_book.js
Last active Oct 12, 2020
Order Book Matching Engine
View order_book.js
function order_book(orders) {
return orders.reduce((executedQuantity, currentOrder, currentOrderIndex) => {
if (currentOrderIndex === 0) return executedQuantity;
const matchingOrders = find_matching_orders(orders.slice(0, currentOrderIndex), currentOrder);
if (!matchingOrders.length) return executedQuantity;
for (let matchingOrderIndex = 0; matchingOrderIndex < matchingOrders.length; matchingOrderIndex++) {
const currentOrderQuantity = parseInt(currentOrder[1], 0);
if (currentOrderQuantity === 0) break;
const matchingOrder = orders[matchingOrders[matchingOrderIndex].i];
const matchingOrderQuantity = parseInt(matchingOrder[1], 0);
@Gerst20051
Gerst20051 / beHappy.js
Last active Oct 12, 2020
Be Happy Coding Challenge
View beHappy.js
/*
* Complete the 'beHappy' function below.
*
* The function is expected to return an INTEGER_ARRAY.
* The function accepts following parameters:
* 1. DOUBLE sightRadius
* 2. 2D_INTEGER_ARRAY eventList
*/
function beHappy(sightRadius, eventList) {
@Gerst20051
Gerst20051 / closingTime.js
Last active Oct 12, 2020
Closing Time Coding Challenge
View closingTime.js
/*
* Complete the 'closingTime' function below.
*
* The function is expected to return an INTEGER.
* The function accepts following parameters:
* 1. INTEGER_ARRAY queue
* 2. DOUBLE admission
* 3. DOUBLE runningCost
*/
@Gerst20051
Gerst20051 / github-api-repos-query.graphql
Created Apr 22, 2020
GitHub GraphQL API Repos Query
View github-api-repos-query.graphql
# https://developer.github.com/v3/
# https://developer.github.com/v4/
# https://developer.github.com/v4/explorer/
{
viewer {
repositories(isFork: false, first: 100, orderBy: { field: NAME, direction: ASC }) {
pageInfo {
endCursor
}
@Gerst20051
Gerst20051 / unflatten.php
Last active Jun 26, 2020
PHP Unflatten Dot Notation Array
View unflatten.php
<?
$results = [
'id' => 'abc123',
'address.id' => 'def456',
'address.coordinates.lat' => '12.345',
'address.coordinates.lng' => '67.89',
'address.coordinates.geo.accurate' => true,
];
View JsPrettier.sublime-settings
{
"prettier_options": {
"arrowParens": "avoid",
"bracketSpacing": true,
"printWidth": 100,
"singleQuote": true,
"trailingComma": "all"
}
}
View save_weights.py
import math
import random
import pickle
import os
class NeuralNetwork():
def __init__(self):
# Seed the random number generator, so we get the same random numbers each time
random.seed(1)
You can’t perform that action at this time.