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
| class Node { | |
| constructor(data) { | |
| this.data = data | |
| this.next = null | |
| } | |
| } | |
| class SinglyList { | |
| constructor() { | |
| this._length = 0; |
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
| const count = names => names.reduce((acc, name) => Object.assign(acc, {[name]: (acc[name] || 0) + 1}), {}) | |
| const duplicates = dict => Object.keys(dict).filter((a) => dict[a] > 1) | |
| const getDuplicates = vals => duplicates(count(vals)) | |
| export default getDuplicates |
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
| class Queue { | |
| constructor() { | |
| this._oldestIndex = 1 | |
| this._newestIndex = 1 | |
| this._storage = {} | |
| } | |
| getStorage() { | |
| return this._storage | |
| } | |
| getSize() { |
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
| class Stack { | |
| constructor() { | |
| this._size = 0 | |
| this._storage = {} | |
| } | |
| getSize() { | |
| return this._size | |
| } | |
| getStorage() { | |
| return this._storage |
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
| const a = new Set([1, 2, 3, 4, 4, 4]) | |
| const b = new Set([3, 4, 5, 6]) | |
| const intersect = (set1, set2) => [...set1].filter(num => set2.has(num)) | |
| const differ = (set1, set2) => [...set1].filter(num => !set2.has(num)) | |
| const joinSet = (set1, set2) => [...set1, ...set2] | |
| const myIntersectedSet = new Set(intersect(a, b)) | |
| console.log('myIntersectedSet', myIntersectedSet) |
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
| // fmap | |
| precedencegroup ComparisonPrecedence { | |
| associativity: left | |
| } | |
| infix operator <^> : ComparisonPrecedence | |
| func <^><A, B>(f: (A) -> B, a: A?) -> B? { | |
| switch a { | |
| case .some(let x): |
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
| const head = ([h, ...tail]) => h | |
| const defaultTo = (defaultValue, testValue) => Boolean(testValue) ? testValue : defaultValue | |
| const capture = (evt) => { | |
| const eventTarget = evt.target | |
| const touchTarget = evt.touches && evt.touches.length > 0 | |
| const xPos = touchTarget ? head(touchTarget).clientX : evt.clientX | |
| const yPos = touchTarget ? head(touchTarget).clientY : evt.clientY |
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
| module Main exposing (..) | |
| import Html exposing (..) | |
| import Html.Attributes exposing (..) | |
| import Html.Events exposing (onInput) | |
| main = | |
| program | |
| { init = init |
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 Html exposing (..) | |
| import Html.Attributes exposing (..) | |
| import Html.Events exposing (onInput) | |
| import Array exposing (Array) | |
| main = | |
| program | |
| { | |
| init = init, | |
| update = update, |
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
| // Either | |
| const Right = x => ({ | |
| map: fn => Right(fn(x)), | |
| fold: (f, g) => g(x), | |
| inspect: () => `Right(${x})` | |
| }) | |
| const Left = x => ({ | |
| map: fn => Left(x), | |
| fold: (f, g) => f(x), |