Skip to content

Instantly share code, notes, and snippets.

View krnsk0's full-sized avatar
🤔

Jon Kurinsky krnsk0

🤔
View GitHub Profile
@krnsk0
krnsk0 / riverSizes.md
Last active May 18, 2022 14:20
River Sizes Prompt & Solution

River Sizes

Prompt

You are given a two-dimensional array of potentially unequal height and width. It contains only 0s and 1s. This array represents a map: 0s are land, and 1s are water. A "river" on this map consists of any number of contiguous, adjacent water squares, where "adjacent" means "above", "below", "to the left of", or "to the right of" (that is, diagonal squares are not adjacent). Write a function which returns an array of the sizes of all rivers represented in the input matrix. Note that these sizes do not need to be in any particular order.

For example:

const input = [
@krnsk0
krnsk0 / currying.md
Last active July 10, 2019 14:35
variadic currying reacto

Variadic Curry

Prompt

'Curry' is a name for a utility function commonly employed in a functional programming context. Typically, the curry function takes in a function with arity N ('arity' simply means 'the number of arguments a function takes') and returns a function with an arity of 1.

When called, the returned function applies its argument to the original function, and then returns a new function with arity of one. When called, this returned function applies its argument, in turn, returning another function with an arity of one, and so on-- until all of the arguments have been passed in to the original function, at which point it is actually called and the actual result is returned.

We can manually curry funcitons without a currying utility function. For example: