This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
type: "button" | |
icon: "octoface" | |
tooltip: "Open in Github" | |
callback: "open-on-github:file" | |
} | |
{ | |
type: "button" | |
icon: "document" |