Skip to content

Instantly share code, notes, and snippets.

View abadfish's full-sized avatar

Kirsten Lee Burton abadfish

  • Ollie Pets
  • Ridgefield, CT
View GitHub Profile
import React, { useState, useCallback } from 'react'
export const useStatePair = (initial) => {
const [[prev, current], setPair] = useState([undefined, initial])
const setValue = useCallback(
next => setPair([current, next]),
[current]
)
return [prev, current, setValue]
}
@abadfish
abadfish / find_pairs.rb
Created February 8, 2017 18:20
Find pairs in array with difference of n
number_list = [4, 3, 33, 237, 2, 95, 17, 6, 67, 9, 19, 54, 8, 18, 25, 31, 1, 101, 234, 236, 100, 63, 68, 69]
input = 2
def find_pairs(array)
pairs = []
array.each_with_index do |px1, i|
for px2 in array[i+1..-1]
potential_difference1 = px2 - px1
potential_difference2 = px1 - px2
input = 2
@abadfish
abadfish / biggest_loss
Created December 29, 2016 03:32
Technical Question from Mock Interview with Funnel interviewer Bradley Gunn
def biggest_loss(prices)
max_loss = 0
prices.each_with_index do |px1, day| # n days as index
for px2 in prices[day+1..-1] # iterate through all days once
potential_loss = px1 - px2 # buy at price 1 and sell at price 2
if potential_loss > max_loss
max_loss = potential_loss
end
end
[
{
type: "button"
icon: "octoface"
tooltip: "Open in Github"
callback: "open-on-github:file"
}
{
type: "button"
icon: "document"