Skip to content

Instantly share code, notes, and snippets.


Tony Brown anthonybrown

Block or report user

Report or block anthonybrown

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
anthonybrown / twittermute.txt
Created Jan 24, 2020 — forked from IanColdwater/twittermute.txt
Here are some terms to mute on Twitter to clean your timeline up a bit.
View twittermute.txt
Mute these words in your settings here:
View getFirstLast.js
function getFirstLast(array) {
const {
0: first,
length: len,
[len - 1]: last
} = array
return {first, last}
anthonybrown / App.js
Created Sep 3, 2019
React Cheat Sheet: --> Context, Refs, Memo, Lazy, Suspense
View App.js
// createContext
const WeatherContext = React.createContext({ day: 3 })
const App = ({ children }) => {
const [weather, setWeather] = React.useState(null)
const [error, setError] = React.useState(null)
React.useEffect(() => {
}, [])
anthonybrown / bigArr.js
Created Sep 2, 2019
Shorter code isn't always better code.
View bigArr.js
const bigArr = new Array(1000000).fill(1).map((_, i) => i);
bigArr[100] = 5;
const allUnique = arr => {
const all = new Set();
for (let el of arr) {
if (all.has(el)) {
return false;
anthonybrown / learn-curry.js
Last active Aug 30, 2019
example of using curried functions
View learn-curry.js
/** Store Data */
const prices = {
game: 59.95,
nintendo: 399.99,
controller: 49.99,
xbox: 299.99,
ps1: 349.99
const basket = [
anthonybrown / curried.js
Last active Aug 30, 2019
A simple example of currying in functional JavaScript
View curried.js
function greetCurried(greeting) {
return function(name) {
if (typeof(greeting) !== 'string') {
return ('Greetings!')
} else if (typeof(name) !== 'string') {
return (greeting)
return (`${greeting}, ${name}`)
anthonybrown / add.js
Last active Aug 15, 2019
Using closures, higher order functions to have a stateful function
View add.js
function getAdd() {
let foo = 0;
return function() {
foo = foo + 1;
return foo;
const add = getAdd()
View symbolToPrimitive.js
class Decimal {
constructor(number) {
this.precision = 8
this.number = number
this.integer = Math.floor(number)
this.fractional = Math.round(number * Math.pow(10, this.precision))
[Symbol.toPrimitive](hint) {
// hint can be: string, number, default
anthonybrown /
Created Jul 20, 2019 — forked from ljharb/
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.


JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

You can’t perform that action at this time.