• Stars
    star
    732
  • Rank 61,915 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A list of small & fun functional programming exercises in JavaScript

js-function-fun

A list of small & fun functional programming exercises in JavaScript.

Contributing

Please see CONTRIBUTING.

Testing

To test the functions:

  1. Run npm install to install the dependencies (need node.js for npm). If you don't have node please visit the Node JS website to download. It is recommended to download the LTS version.
  2. Change filename in test/tests.js to the name of your solution file (optional).
  3. Make sure your solution file is in the Solutions folder.
  4. Make sure your function names match the ones listed below as you're coding them.
  5. At the bottom of your solution file, copy and paste the following code:
module.exports = {
    identity,
    addb,
    subb,
    mulb,
    minb,
    maxb,
    add,
    sub,
    mul,
    min,
    max,
    addRecurse,
    mulRecurse,
    minRecurse,
    maxRecurse,
    not,
    acc,
    accPartial,
    accRecurse,
    fill,
    fillRecurse,
    set,
    identityf,
    addf,
    liftf,
    pure,
    curryb,
    curry,
    inc,
    twiceUnary,
    doubl,
    square,
    twice,
    reverseb,
    reverse,
    composeuTwo,
    composeu,
    composeb,
    composeTwo,
    compose,
    limitb,
    limit,
    genFrom,
    genTo,
    genFromTo,
    elementGen,
    element,
    collect,
    filter,
    filterTail,
    concatTwo,
    concat,
    concatTail,
    gensymf,
    gensymff,
    fibonaccif,
    counter,
    revocableb,
    revocable,
    extract,
    m,
    addmTwo,
    addm,
    liftmbM,
    liftmb,
    liftm,
    exp,
    expn,
    addg,
    liftg,
    arrayg,
    continuizeu,
    continuize,
    vector,
    exploitVector,
    vectorSafe,
    pubsub,
    mapRecurse,
    filterRecurse,
};
  1. You can comment out any function names in the module.exports that you haven't written yet, but a lot of the tests depend on previous functions to run properly so it's safer to write the functions in order.
  2. Finally, npm run test to run the tests.

Functions

identity(x) β‡’ any

Write a function identity that takes an argument and returns that argument

addb(a, b) β‡’ number

Write a binary function addb that takes two numbers and returns their sum

subb(a, b) β‡’ number

Write a binary function subb that takes two numbers and returns their difference

mulb(a, b) β‡’ number

Write a binary function mulb that takes two numbers and returns their product

minb(a, b) β‡’ number

Write a binary function minb that takes two numbers and returns the smaller one

maxb(a, b) β‡’ number

Write a binary function maxb that takes two numbers and returns the larger one

add(...nums) β‡’ number

Write a function add that is generalized for any amount of arguments

sub(...nums) β‡’ number

Write a function sub that is generalized for any amount of arguments

mul(...nums) β‡’ number

Write a function mul that is generalized for any amount of arguments

min(...nums) β‡’ number

Write a function min that is generalized for any amount of arguments

max(...nums) β‡’ number

Write a function max that is generalized for any amount of arguments

addRecurse(...nums) β‡’ number

Write a function addRecurse that is the generalized add function but uses recursion

mulRecurse(...nums) β‡’ number

Write a function mulRecurse that is the generalized mul function but uses recursion

minRecurse(...nums) β‡’ number

Write a function minRecurse that is the generalized min function but uses recursion

maxRecurse(...nums) β‡’ number

Write a function maxRecurse that is the generalized max function but uses recursion

not(func) β‡’ function

Write a function not that takes a function and returns the negation of its result

acc(func, initial) β‡’ function

Write a function acc that takes a function and an initial value and returns a function that runs the initial function on each argument, accumulating the result

accPartial(func, start, end) β‡’ function

Write a function accPartial that takes in a function, a start index, and an end index, and returns a function that accumulates a subset of its arguments by applying the given function to all elements between start and end.

accRecurse(func, initial) β‡’ function

Write a function accRecurse that does what acc does but uses recursion

fill(num) β‡’ array

Write a function fill that takes a number and returns an array with that many numbers equal to the given number

fillRecurse(num) β‡’ array

Write a function fillRecurse that does what fill does but uses recursion

set(...args) β‡’ array

Write a function set that is given a list of arguments and returns an array with all duplicates removed

identityf(x) β‡’ function

Write a function identityf that takes an argument and returns a function that returns that argument

addf(a) β‡’ function

Write a function addf that adds from two invocations

liftf(binary) β‡’ function

Write a function liftf that takes a binary function, and makes it callable with two invocations

pure(x, y) β‡’ array

Write a pure function pure that is a wrapper arround the impure function impure

function impure(x) {
  y++;
  z = x * y;
}

var y = 5, z;

impure(20);
z; // 120

impure(25);
z; // 175
curryb(binary, a) β‡’ function

Write a function curryb that takes a binary function and an argument, and returns a function that can take a second argument

curry(func, ...outer) β‡’ function

Write a function curry that is generalized for any amount of arguments

inc(x) β‡’ number

Without writting any new functions, show multiple ways to create the inc function

twiceUnary(binary) β‡’ function

Write a function twiceUnary that takes a binary function and returns a unary function that passes its argument to the binary function twice

doubl(x) β‡’ number

Use the function twiceUnary to create the doubl function

square(x) β‡’ number

Use the function twiceUnary to create the square function

twice(x) β‡’ any

Write a function twice that is generalized for any amount of arguments

reverseb(binary) β‡’ function

Write a function reverseb that reverses the arguments of a binary function

reverse(func) β‡’ function

Write a function reverse that is generalized for any amount of arguments

composeuTwo(unary1, unary2) β‡’ function

Write a function composeuTwo that takes two unary functions and returns a unary function that calls them both

composeu(...funcs) β‡’ any

Write a function composeu that is generalized for any amount of arguments

composeb(binary1, binary2) β‡’ function

Write a function composeb that takes two binary functions and returns a function that calls them both

composeTwo(func1, func2) β‡’ function

Write a function composeTwo that takes two functions and returns a function that calls them both

compose(...funcs) β‡’ function

Write a function compose that takes any amount of functions and returns a function that takes any amount of arguments and gives them to the first function, then that result to the second function and so on

limitb(binary, lmt) β‡’ function

Write a function limitb that allows a binary function to be called a limited number of times

limit(func, lmt) β‡’ function

Write a function limit that is generalized for any amount of arguments

genFrom(x) β‡’ function

Write a function genFrom that produces a generator that will produces a series of values

genTo(gen, lmt) β‡’ function

Write a function genTo that takes a generator and an end limit, and returns a generator that will produce numbers up to that limit

genFromTo(start, end) β‡’ function

Write a function genFromTo that produces a generator that will produce values in a range

elementGen(array, gen) β‡’ function

Write a function elementGen that takes an array and a generator and returns a generator that will produce elements from the array

element(array, gen) β‡’ function

Write a function element that is a modified elementGen function so that the generator argument is optional. If a generator is not provided, then each of the elements of the array will be produced.

collect(gen, array) β‡’ function

Write a function collect that takes a generator and an array and produces a function that will collect the results in the array

filter(gen, predicate) β‡’ function

Write a function filter that takes a generator and a predicate and produces a generator that produces only the values approved by the predicate

filterTail(gen, predicate) β‡’ function

Write a function filterTail that uses tail-recursion to perform the filtering

concatTwo(gen1, gen2) β‡’ function

Write a function concatTwo that takes two generators and produces a generator that combines the sequences

concat(...gens) β‡’ function

Write a function concat that is generalized for any amount of arguments

concatTail(...gens) β‡’ function

Write a function concatTail that uses tail-recursion to perform the concating

gensymf(symbol) β‡’ function

Write a function gensymf that makes a function that generates unique symbols

gensymff(unary, seed) β‡’ function

Write a function gensymff that takes a unary function and a seed and returns a gensymf

fibonaccif(first, second) β‡’ function

Write a function fibonaccif that returns a generator that will return the next fibonacci number

counter(i) β‡’ object

Write a function counter that returns an object containing two functions that implement an up/down counter, hiding the counter

revocableb(binary) β‡’ object

Write a function revocableb that takes a binary function, and returns an object containing an invoke function that can invoke a function and a revoke function that disables the invoke function

revocable(func) β‡’ object

Write a function revocable that is generalized for any amount of arguments

extract(array, prop) β‡’ array

Write a function extract that takes an array of objects and an object property name and converts each object in the array by extracting that property

m(value, source) β‡’ object

Write a function m that takes a value and an optional source string and returns them in an object

addmTwo(m1, m2) β‡’ object

Write a function addmTwo that adds two m objects and returns an m object

addm(...ms) β‡’ object

Write a function addm that is generalized for any amount of arguments

liftmbM(binary, op) β‡’ object

Write a function liftmbM that takes a binary function and a string and returns a function that acts on m objects

liftmb(binary, op) β‡’ object

Write a function liftmb that is a modified function liftmbM that can accept arguments that are either numbers or m objects

liftm(func, op) β‡’ object

Write a function liftm that is generalized for any amount of arguments

exp(value) β‡’ any

Write a function exp that evaluates simple array expressions

expn(value) β‡’ any

Write a function expn that is a modified exp that can evaluate nested array expressions

addg(value) β‡’ number | undefined

Write a function addg that adds from many invocations, until it sees an empty invocation

liftg(binary) β‡’ function

Write a function liftg that will take a binary function and apply it to many invocations

arrayg(value) β‡’ array

Write a function arrayg that will build an array from many invocations

continuizeu(unary) β‡’ function

Write a function continuizeu that takes a unary function and returns a function that takes a callback and an argument

continuize(func) β‡’ function

Write a function continuize that takes a function and returns a function that takes a callback and arguments

vector()

Make an array wrapper object with methods get, store, and append, such that an attacker cannot get access to the private array

exploitVector()

Let's assume your vector implementation looks like something like this:

let vector = () => {
  let array = []
  return {
    append: (v) => array.push(v),
    get: (i) => array[i],
    store: (i, v) => array[i] = v
  }
}

Can you spot any security concerns with this approach? Mainly, can we get access to the array outside of vector? Note: the issue has nothing to do with prototypes and we can assume that global prototypes cannot be altered. Hint: Think about using this in a method invocation. Can we override a method of vector?

vectorSafe()

How would you rewrite vector to deal with the issue from above?

pubsub()

Make a function pubsub that makes a publish/subscribe object. It will reliably deliver all publications to all subscribers in the right order.

mapRecurse(array, callback) β‡’ array

Make a function mapRecurse that performs a transformation for each element of a given array, recursively

filterRecurse(array, predicate) β‡’ array

Make a function filterRecurse that takes in an array and a predicate function and returns a new array by filtering out all items using the predicate, recursively.

identity(x) β‡’ any

Write a function identity that takes an argument and returns that argument

Param Type
x any

Example

identity(3) // 3

addb(a, b) β‡’ number

Write a binary function addb that takes two numbers and returns their sum

Param Type
a number
b number

Example

addb(3, 4) // 3 + 4 = 7

subb(a, b) β‡’ number

Write a binary function subb that takes two numbers and returns their difference

Param Type
a number
b number

Example

subb(3, 4) // 3 - 4 = -1

mulb(a, b) β‡’ number

Write a binary function mulb that takes two numbers and returns their product

Param Type
a number
b number

Example

mulb(3, 4) // 3 * 4 = 12

minb(a, b) β‡’ number

Write a binary function minb that takes two numbers and returns the smaller one

Param Type
a number
b number

Example

minb(3, 4) // 3

maxb(a, b) β‡’ number

Write a binary function maxb that takes two numbers and returns the larger one

Param Type
a number
b number

Example

maxb(3, 4) // 4

add(...nums) β‡’ number

Write a function add that is generalized for any amount of arguments

Param Type
...nums number

Example

add(1, 2, 4) // 1 + 2 + 4 = 7

sub(...nums) β‡’ number

Write a function sub that is generalized for any amount of arguments

Param Type
...nums number

Example

sub(1, 2, 4) // 1 - 2 - 4 = -5

mul(...nums) β‡’ number

Write a function mul that is generalized for any amount of arguments

Param Type
...nums number

Example

mul(1, 2, 4) // 1 * 2 * 4 = 8

min(...nums) β‡’ number

Write a function min that is generalized for any amount of arguments

Param Type
...nums number

Example

min(1, 2, 4) // 1

max(...nums) β‡’ number

Write a function max that is generalized for any amount of arguments

Param Type
...nums number

Example

max(1, 2, 4) // 4

addRecurse(...nums) β‡’ number

Write a function addRecurse that is the generalized add function but uses recursion

Param Type
...nums number

Example

addRecurse(1, 2, 4) // 1 + 2 + 4 = 7

mulRecurse(...nums) β‡’ number

Write a function mulRecurse that is the generalized mul function but uses recursion

Param Type
...nums number

Example

mulRecurse(1, 2, 4) // 1 * 2 * 4 = 8

minRecurse(...nums) β‡’ number

Write a function minRecurse that is the generalized min function but uses recursion

Param Type
...nums number

Example

minRecurse(1, 2, 4) // 1

maxRecurse(...nums) β‡’ number

Write a function maxRecurse that is the generalized max function but uses recursion

Param Type
...nums number

Example

maxRecurse(1, 2, 4) // 4

not(func) β‡’ function

Write a function not that takes a function and returns the negation of its result

Param Type
func function

Example

const isOdd = (x) => x % 2 === 1
const isEven = not(isOdd)
isEven(1) // false
isEven(2) // true

acc(func, initial) β‡’ function

Write a function acc that takes a function and an initial value and returns a function that runs the initial function on each argument, accumulating the result

Param Type
func function
initial any

Example

let add = acc(addb, 0)
add(1, 2, 4) // 7

let mul = acc(mulb, 1)
mul(1, 2, 4) // 8

accPartial(func, start, end) β‡’ function

Write a function accPartial that takes in a function, a start index, and an end index, and returns a function that accumulates a subset of its arguments by applying the given function to all elements between start and end.

Param Type
func function
start number
end number

Example

const addSecondToThird = accPartial(add, 1, 3)
addSecondToThird(1, 2, 4, 8) // [ 1, 6, 8 ]

accRecurse(func, initial) β‡’ function

Write a function accRecurse that does what acc does but uses recursion

Param Type
func function
initial number

Example

let add = accRecurse(addb, 0)
add(1, 2, 4) // 7

let mul = accRecurse(mulb, 1)
mul(1, 2, 4) // 8

fill(num) β‡’ array

Write a function fill that takes a number and returns an array with that many numbers equal to the given number

Param Type
num number

Example

fill(3) // [ 3, 3, 3 ]

fillRecurse(num) β‡’ array

Write a function fillRecurse that does what fill does but uses recursion

Param Type
num number

Example

fillRecurse(3) // [ 3, 3, 3 ]

set(...args) β‡’ array

Write a function set that is given a list of arguments and returns an array with all duplicates removed

Param Type
...args any

Example

let oneAndTwo = set(1, 1, 1, 2, 2, 2) // [ 1, 2 ]

identityf(x) β‡’ function

Write a function identityf that takes an argument and returns a function that returns that argument

Param Type
x any

Example

let three = identityf(3)
three() // 3

addf(a) β‡’ function

Write a function addf that adds from two invocations

Param Type
a number

Example

addf(3)(4) // 7

liftf(binary) β‡’ function

Write a function liftf that takes a binary function, and makes it callable with two invocations

Param Type
binary function

Example

let addf = liftf(addb)
addf(3)(4) // 7

liftf(mulb)(5)(6) // 30

pure(x, y) β‡’ array

Write a pure function pure that is a wrapper arround the impure function impure

function impure(x) {
  y++;
  z = x * y;
}

var y = 5, z;

impure(20);
z; // 120

impure(25);
z; // 175

Returns: array - an array containing y and z

Param Type
x number
y number

Example

pure(20, 5) // [ 6, 120 ]
pure(25, 6) // [ 7, 175 ]

curryb(binary, a) β‡’ function

Write a function curryb that takes a binary function and an argument, and returns a function that can take a second argument

Param Type
binary function
a any

Example

let add3 = curryb(addb, 3)
add3(4) // 7

curryb(mulb, 5)(6) // 30

curry(func, ...outer) β‡’ function

Write a function curry that is generalized for any amount of arguments

Param Type
func function
...outer any

Example

curry(add, 1, 2, 4)(4, 2, 1) = 1 + 2 + 4 + 4 + 2 + 1 = 14
curry(sub, 1, 2, 4)(4, 2, 1) = 1 - 2 - 4 - 4 - 2 - 1 = -12
curry(mul, 1, 2, 4)(4, 2, 1) = 1 * 2 * 4 * 4 * 2 * 1 = 64

inc(x) β‡’ number

Without writting any new functions, show multiple ways to create the inc function

Param Type
x number

Example

inc(5) // 6
inc(inc(5)) // 7

twiceUnary(binary) β‡’ function

Write a function twiceUnary that takes a binary function and returns a unary function that passes its argument to the binary function twice

Param Type
binary function

Example

let doubl = twiceUnary(addb)
doubl(11) // 22

let square = twiceUnary(mulb)
square(11) // 121

doubl(x) β‡’ number

Use the function twiceUnary to create the doubl function

Param Type
x number

Example

doubl(11) // 22

square(x) β‡’ number

Use the function twiceUnary to create the square function

Param Type
x number

Example

square(11) // 121

twice(x) β‡’ any

Write a function twice that is generalized for any amount of arguments

Param Type
x function

Example

let doubleSum = twice(add)
doubleSum(1, 2, 4) // 1 + 2 + 4 + 1 + 2 + 4 = 14

reverseb(binary) β‡’ function

Write a function reverseb that reverses the arguments of a binary function

Param Type
binary function

Example

let bus = reverseb(subb)
bus(3, 2) // -1

reverse(func) β‡’ function

Write a function reverse that is generalized for any amount of arguments

Param Type
func function

Example

reverse(sub)(1, 2, 4) // 4 - 2 - 1 = 1

composeuTwo(unary1, unary2) β‡’ function

Write a function composeuTwo that takes two unary functions and returns a unary function that calls them both

Param Type
unary1 function
unary2 function

Example

composeuTwo(doubl, square)(5) // (5 * 2)^2 = 100

composeu(...funcs) β‡’ any

Write a function composeu that is generalized for any amount of arguments

Param Type
...funcs function

Example

composeu(doubl, square, identity, curry(add, 1, 2))(5) // (5 * 2)^2 + 1 + 2 = 103

composeb(binary1, binary2) β‡’ function

Write a function composeb that takes two binary functions and returns a function that calls them both

Param Type
binary1 function
binary2 function

Example

composeb(addb, mulb)(2, 3, 7) // (2 + 3) * 7 = 35

composeTwo(func1, func2) β‡’ function

Write a function composeTwo that takes two functions and returns a function that calls them both

Param Type
func1 function
func2 function

Example

composeTwo(add, square)(2, 3, 7, 5) // (2 + 3 + 7 + 5)^2 = 289

compose(...funcs) β‡’ function

Write a function compose that takes any amount of functions and returns a function that takes any amount of arguments and gives them to the first function, then that result to the second function and so on

Param Type
...funcs function

Example

const f = compose(add, doubl, fill, max)
f(0, 1, 2)
// add(0, 1, 2) -> 3
// doubl(3) -> 6
// fill(6) -> [ 6, 6, 6, 6, 6, 6 ]
// max(6, 6, 6, 6, 6, 6) -> 6

limitb(binary, lmt) β‡’ function

Write a function limitb that allows a binary function to be called a limited number of times

Param Type
binary function
lmt number

Example

let addLmtb = limitb(addb, 1)
addLmtb(3, 4) // 7
addLmtb(3, 5) // undefined

limit(func, lmt) β‡’ function

Write a function limit that is generalized for any amount of arguments

Param Type
func function
lmt number

Example

let addLmt = limit(add, 1)
addLmt(1, 2, 4) // 7
addLmt(3, 5, 9, 2) // undefined

genFrom(x) β‡’ function

Write a function genFrom that produces a generator that will produces a series of values. Follows the iterator protocol for the returned format.

Param Type
x number

Example

let index = genFrom(0)

index.next().value // 0
index.next().value // 1
index.next().value // 2

genTo(gen, lmt) β‡’ function

Write a function genTo that takes a generator and an end limit, and returns a generator that will produce numbers up to that limit

Param Type
gen function
lmt number

Example

let index = genTo(genFrom(1), 3)

index.next().value // 1
index.next().value // 2
index.next().value // undefined

genFromTo(start, end) β‡’ function

Write a function genFromTo that produces a generator that will produce values in a range

Param Type
start number
end number

Example

let index = genFromTo(0, 3)
index.next().value // 0
index.next().value // 1
index.next().value // 2
index.next().value // undefined

elementGen(array, gen) β‡’ function

Write a function elementGen that takes an array and a generator and returns a generator that will produce elements from the array

Param Type
array array
gen function

Example

let ele = elementGen(['a', 'b', 'c', 'd'], genFromTo(1, 3))

ele.next().value // 'b'
ele.next().value // 'c'
ele.next().value // undefined

element(array, gen) β‡’ function

Write a function element that is a modified elementGen function so that the generator argument is optional. If a generator is not provided, then each of the elements of the array will be produced.

Param Type
array array
gen function

Example

let ele = element(['a', 'b', 'c', 'd'])

ele.next().value // 'a'
ele.next().value // 'b'
ele.next().value // 'c'
ele.next().value // 'd'
ele.next().value // undefined

collect(gen, array) β‡’ function

Write a function collect that takes a generator and an array and produces a function that will collect the results in the array

Param Type
gen function
array array

Example

let array = []
let col = collect(genFromTo(0, 2), array)

col.next().value // 0
col.next().value // 1
col.next().value // undefined
array // [0, 1]

filter(gen, predicate) β‡’ function

Write a function filter that takes a generator and a predicate and produces a generator that produces only the values approved by the predicate

Param Type
gen function
predicate function

Example

let third = (val) => val % 3 === 0
let fil = filter(genFromTo(0, 5), third)

fil.next().value // 0
fil.next().value // 3
fil.next().value // undefined

filterTail(gen, predicate) β‡’ function

Write a function filterTail that uses tail-recursion to perform the filtering

Param Type
gen function
predicate function

Example

let third = (val) => val % 3 === 0
let fil = filterTail(genFromTo(0, 5), third)

fil.next().value // 0
fil.next().value // 3
fil.next().value // undefined

concatTwo(gen1, gen2) β‡’ function

Write a function concatTwo that takes two generators and produces a generator that combines the sequences

Param Type
gen1 function
gen2 function

Example

let con = concatTwo(genFromTo(0, 3), genFromTo(0, 2))
con.next().value // 0
con.next().value // 1
con.next().value // 2
con.next().value // 0
con.next().value // 1
con.next().value // undefined

concat(...gens) β‡’ function

Write a function concat that is generalized for any amount of arguments

Param Type
...gens function

Example

let con = concat(genFromTo(0, 3), genFromTo(0, 2), genFromTo(5, 7))
con.next().value // 0
con.next().value // 1
con.next().value // 2
con.next().value // 0
con.next().value // 1
con.next().value // 5
con.next().value // 6
con.next().value // undefined

concatTail(...gens) β‡’ function

Write a function concatTail that uses tail-recursion to perform the concating

Param Type
...gens function

Example

let con = concatTail(genFromTo(0, 3), genFromTo(0, 2), genFromTo(5, 7))
con.next().value // 0
con.next().value // 1
con.next().value // 2
con.next().value // 0
con.next().value // 1
con.next().value // 5
con.next().value // 6
con.next().value // undefined

gensymf(symbol) β‡’ function

Write a function gensymf that makes a function that generates unique symbols

Param Type
symbol string

Example

let genG = gensymf('G')
let genH = gensymf('H')

genG.next().value // 'G1'
genH.next().value // 'H1'
genG.next().value // 'G2'
genH.next().value // 'H2'

gensymff(unary, seed) β‡’ function

Write a function gensymff that takes a unary function and a seed and returns a gensymf

Param Type
unary function
seed number

Example

let gensymf = gensymff(inc, 0)
let genG = gensymf('G')
let genH = gensymf('H')

genG.next().value // 'G1'
genH.next().value // 'H1'
genG.next().value // 'G2'
genH.next().value // 'H2'

fibonaccif(first, second) β‡’ function

Write a function fibonaccif that returns a generator that will return the next fibonacci number

Param Type
first number
second number

Example

let fib = fibonaccif(0, 1)
fib.next().value // 0
fib.next().value // 1
fib.next().value // 1
fib.next().value // 2
fib.next().value // 3
fib.next().value // 5
fib.next().value // 8

counter(i) β‡’ object

Write a function counter that returns an object containing two functions that implement an up/down counter, hiding the counter

Param Type
i number

Example

let obj = counter(10)
let { up, down } = obj

up() // 11
down() // 10
down() // 9
up() // 10

revocableb(binary) β‡’ object

Write a function revocableb that takes a binary function, and returns an object containing an invoke function that can invoke a function and a revoke function that disables the invoke function

Param Type
binary function

Example

let rev = revocableb(addb)

rev.invoke(3, 4) // 7
rev.revoke()
rev.invoke(5, 7) // undefined

revocable(func) β‡’ object

Write a function revocable that is generalized for any amount of arguments

Param Type
func function

Example

let rev = revocable(add)

rev.invoke(3, 4) // 7
rev.revoke()
rev.invoke(5, 7) // undefined

extract(array, prop) β‡’ array

Write a function extract that takes an array of objects and an object property name and converts each object in the array by extracting that property

Param Type
array array
prop string

Example

let people = [{ name: 'john' }, { name: 'bob' }]
let names = extract(people, 'name') // ['john', 'bob']

m(value, source) β‡’ object

Write a function m that takes a value and an optional source string and returns them in an object

Param Type
value any
source any

Example

m(1) // {value:1, source:"1"}

m(Math.PI, 'pi') // {value:3.14159..., source:"pi"}

addmTwo(m1, m2) β‡’ object

Write a function addmTwo that adds two m objects and returns an m object

Param Type
m1 function
m2 function

Example

addmTwo(m(3), m(4)) // {value:7, source:"(3+4)"}

addmTwo(m(1, m(Math.PI, 'pi'))) // {value:4.14159..., source:"(1+pi)"}

addm(...ms) β‡’ object

Write a function addm that is generalized for any amount of arguments

Param Type
...ms function

Example

addm(m(1), m(2), m(4)) // {value:7, source:"(1+2+4)"}

liftmbM(binary, op) β‡’ object

Write a function liftmbM that takes a binary function and a string and returns a function that acts on m objects

Param Type
binary function
op string

Example

let addmb = liftmbM(addb, '+')

addmb(m(3), m(4)) // {value:7, source:"(3+4)"}

liftmbM(mul, '*')(m(3), m(4)) // {value:12, source:"(3*4)"}

liftmb(binary, op) β‡’ object

Write a function liftmb that is a modified function liftmbM that can accept arguments that are either numbers or m objects

Param Type
binary function
op string

Example

let addmb = liftmb(addb, '+')

addmb(3, 4) // {value:7, source:"(3+4)"}

liftm(func, op) β‡’ object

Write a function liftm that is generalized for any amount of arguments

Param Type
func function
op string

Example

let addm = liftm(add, '+')

addm(m(3), m(4)) // {value:7, source:"(3+4)"}

liftm(mul, '*')(m(3), m(4)) // {value:12, source:"(3*4)"}

exp(value) β‡’ any

Write a function exp that evaluates simple array expressions

Param Type
value any

Example

let sae = [mul, 1, 2, 4]
exp(sae) // 1 * 2 * 4 = 8
exp(42) // 42

expn(value) β‡’ any

Write a function expn that is a modified exp that can evaluate nested array expressions

Param Type
value any

Example

let nae = [Math.sqrt, [add, [square, 3], [square, 4]]]

expn(nae) // sqrt(((3*3)+(4*4))) === 5

addg(value) β‡’ number | undefined

Write a function addg that adds from many invocations, until it sees an empty invocation

Param Type
value number

Example

addg() // undefined
addg(2)() // 2
addg(2)(7)() // 9
addg(3)(0)(4)() // 7
addg(1)(2)(4)(8)() // 15

liftg(binary) β‡’ function

Write a function liftg that will take a binary function and apply it to many invocations

Param Type
binary function

Example

liftg(mulb)() // undefined
liftg(mulb)(3)() // 3
liftg(mulb)(3)(0)(4)() // 0
liftg(mulb)(1)(2)(4)(8)() // 64

arrayg(value) β‡’ array

Write a function arrayg that will build an array from many invocations

Param Type
value any

Example

arrayg() // []
arrayg(3)() // [3]
arrayg(3)(4)(5)() // [3, 4, 5]

continuizeu(unary) β‡’ function

Write a function continuizeu that takes a unary function and returns a function that takes a callback and an argument

Param Type
unary function

Example

let sqrtc = continuizeu(Math.sqrt)
sqrtc(console.log, 81) // logs '9'

continuize(func) β‡’ function

Write a function continuize that takes a function and returns a function that takes a callback and arguments

Param Type
func function

Example

let mullc = continuize(mul)
mullc(console.log, 81, 4, 2) // logs '648'

vector()

Make an array wrapper object with methods get, store, and append, such that an attacker cannot get access to the private array

Example

let v = vector()
v.append(7)
v.store(1, 8)
v.get(0) // 7
v.get(1) // 8

exploitVector()

Let's assume your vector implementation looks like something like this:

let vector = () => {
  let array = []
  return {
    append: (v) => array.push(v),
    get: (i) => array[i],
    store: (i, v) => array[i] = v
  }
}

Can you spot any security concerns with this approach? Mainly, can we get access to the array outside of vector? Note*: the issue has nothing to do with prototypes and we can assume that global prototypes cannot be altered. Hint*: Think about using this in a method invocation. Can we override a method of vector?

Example

let v = vector()
v.append(1)
v.append(2)
let internalData = exploitVector(v) // [1, 2]

vectorSafe()

How would you rewrite vector to deal with the issue from above?

Example

let v = vectorSafe()
v.append(1)
v.append(2)
let internalData = exploitVector(v) // undefined

pubsub()

Make a function pubsub that makes a publish/subscribe object. It will reliably deliver all publications to all subscribers in the right order.

Example

let ps = pubsub()
ps.subscribe(console.log)
ps.publish('It works!') // logs 'It works!'

mapRecurse(array, callback) β‡’ array

Make a function mapRecurse that performs a transformation for each element of a given array, recursively

Param Type
array array
callback function

Example

mapRecurse([1, 2, 3, 4], (x) => x * 2) // [ 2, 4, 6, 8 ]

filterRecurse(array, predicate) β‡’ array

Make a function filterRecurse that takes in an array and a predicate function and returns a new array by filtering out all items using the predicate, recursively.

Param Type
array array
predicate function

Example

filterRecurse([1, 2, 3, 4], (x) => x % 2 === 0) // [ 2, 4 ]

More Repositories

1

start-here-guidelines

Lets Git started in the world of opensource, starting in the Zero To Mastery's opensource playground. Especially designed for education and practical experience purposes.
Python
2,627
star
2

resources

Here is a list of best resources to get you started with learning how to code (mostly related to Web Development). Feel free to add your favorite resources as well and help others in their journey of learning.
HTML
2,592
star
3

complete-web-developer-manual

All resources and notes from the Complete Web Developer: Zero to Mastery course
2,282
star
4

ZtM-Job-Board

βš›οΈ A place for developers to show recruiters they are available for hire
TypeScript
1,102
star
5

javascript20-projects

Student submissions for the JavaScript 20 projects
869
star
6

Animation-Nation

A ZTM Challenge for Hacktoberfest
CSS
336
star
7

CSS-Art

General Edition - A CSS art challenge, for all skill levels
CSS
318
star
8

HTML-project

🌎
HTML
219
star
9

Keiko-Corp

HTML challenge for Hacktoberfest 2020
HTML
206
star
10

old-zero-to-mastery-website

This project once was the Zero To Mastery's website, created entirely by students. It has since been superseded by the new website, but this early version will remain archived for posterity and nostalgia.
JavaScript
201
star
11

Coding_Challenge-8

Realizing the power that you have as a developer to validate business ideas by developing a startups website
165
star
12

Coding_Challenge-6

Logic and problem solving - 3 JavaScript Puzzles
123
star
13

travel-guide

"A travel guide to suggest activities you can do once you arrive to a certain destination. Or you can just browse destinations and check out the different available activities."
JavaScript
112
star
14

Hacktoberfest-2023

Get started with Hacktoberfest 2023 with 3 awesome ZTM projects
103
star
15

book-tracker

"Tracks the amount of books that you've read, the ones you want to read and the progress on the ones you're reading."
CSS
103
star
16

coding_challenge-25

The #30DayProject - What will you build?
74
star
17

Coding_Challenge-3

Build a Speech Recognition Website using IBM Watson!
67
star
18

coding_challenge-46

Build a website with ChatGPT
60
star
19

zero-to-mastery-captions

All captions for The Complete Web Developer in 2020: Zero to Mastery
58
star
20

mappypals

An abandoned student led project. Reach out on Discord if you would like to revive the project!
JavaScript
56
star
21

coding_challenge-18

Solving tough JavaScript questions and improving your core understanding of the language
53
star
22

coding_challenge-24

Advent of Code 2019
52
star
23

ascii-art

A ZTM Hacktoberfest Challenge
Python
52
star
24

drum-root

A React Web App for Creating and Sharing Drum Loops.
JavaScript
48
star
25

coding_challenge-26

COVID 19 pandemic - build software that drive social impact
48
star
26

coding_challenge-42

Hacktoberfest
48
star
27

webblocks-2022

There is a big hype about front-end frameworks all over the place. But in this project we are going to build a showcase library of components using vanilla HTML, CSS and maybe some Javascript.
CSS
48
star
28

breads-client

Keep track of what you read online and see what your friends are reading.
TypeScript
46
star
29

coding_challenge-22

Hacktoberfest 2019
46
star
30

frosty-february-hackathon

Frosty February Hackathon for the ZTM community
45
star
31

coding_challenge-44

Single Page Projects
HTML
45
star
32

coding_challenge-43

Advent of Code
44
star
33

Coding_Challenge-1

Build your own blockchain competition
40
star
34

Advent-of-Code-2022

Advent of Code 2022
40
star
35

project-paycheck

A paycheck-to-paycheck breakdown of income and expenses. An abandoned student led project. Reach out on Discord if you would like to revive the project!
JavaScript
37
star
36

visual-music

An app that converts an uploaded mp3 song into visual expressions. An abandoned student led project. Reach out on Discord if you would like to revive the project!
JavaScript
35
star
37

file-io

Jupyter Notebook
35
star
38

coding_challenge-45

Voice Assistant with Socket.IO, Web Speech API, & Express.
34
star
39

Complete-Python-Developer-Manual

Class notes for Andrei Neagoie's Complete Python Developer course through Zero to Mastery.
Jupyter Notebook
31
star
40

Santafied

A ZTM Challenge for Hacktoberfest 2019
HTML
31
star
41

coding_challenge-33

Advent of Code 2020
30
star
42

coding_challenge-36

Build Your Own Blockchain...
30
star
43

coding_challenge-31

Hacktoberfest 2020
30
star
44

Canvaz

Your favourite annual creative challenge for Hacktoberfest is here! We will once again be showcasing the creative talents of our ZTM students using the HTML <canvas> element.
JavaScript
30
star
45

Hacktoberfest-2022

Hacktoberfest 2022
28
star
46

GrowersBrains

JavaScript
28
star
47

time-collector

This projects counts the time need on each project we do as freelancers or hobbyists, so we better know in the future how to estimate time for projects.
JavaScript
28
star
48

Advent-of-Code

28
star
49

canvas-2022

Your favourite annual creative challenge for Hacktoberfest is here! We will once again be showcasing the creative talents of our ZTM students using the HTML <canvas> element.
JavaScript
27
star
50

coding_challenge-27

Sudoku Goku
25
star
51

python-art

A ZTM Challenge for Hacktoberfest 2019
Python
25
star
52

CSS-Art-Hacktoberfest-Edition

Hacktoberfest Edition - A CSS art challenge, for all skill levels
CSS
25
star
53

coding_challenge-16

Design and build a portfolio project to wow your future customers/employers
24
star
54

coding_challenge-14

Understanding JavaScript and coding without the help of a library or tool
24
star
55

Canvas-Creations

A ZTM Challenge for Hacktoberfest 2020
JavaScript
24
star
56

coding_challenge-15

Simulating a real life work task that you will most likely encounter in your career.
23
star
57

GameSenshi

Hire Your Favorite Gamer! (in development)
CSS
23
star
58

coding_challenge-11

Build a website based on the designs from a fictitious client
HTML
22
star
59

coding_challenge-28

LANGO - The Complete Dev Language API
JavaScript
22
star
60

ascii-art-2021

A ZTM Challenge for Hacktoberfest 2021, converting images into text using the 95 printable characters defined by the ASCII Standard
Python
21
star
61

TheSurvey

This is our very special project, to create a zero to mastery developer survey web app. :) The development branch's result is here:
JavaScript
21
star
62

WebBlocks

zero-to-mastery re-usable web component library.
TypeScript
21
star
63

Coding_Challenge-2

Build an amazing portfolio website!
20
star
64

coding_challenge-34

Date Night
20
star
65

recycling-tracker

"A game style app that tracks the amount of waste that you have recycled and where, then calculates the amount of landfill that you prevented overall. Giving you bragging rights on your favorite social media platform."
JavaScript
20
star
66

CSS_Grid_LearnGame

This will be a game to learn CSS Grid in a Game Mode Style, to make learning more fun!
JavaScript
20
star
67

coding_challenge-35

Building Social Proof
19
star
68

coding_challenge-38

Bomberjam AI
19
star
69

coding_challenge-23

Reverse Engineering Apple Airpods
19
star
70

Halloween-Hacktoberfest-Edition

Hacktoberfest Edition - Halloween themed community challenge, designed with all skill levels in mind!
HTML
19
star
71

coding_challenge-12

Advent of Code 2018 Puzzles
18
star
72

coding_challenge-41

Build Your Own VS Code Extension!
18
star
73

coding_challenge-30

PongPongPong
18
star
74

coding_challenge-19

Building a React based personal blog using GatsbyJS
18
star
75

coding_challenge-39

Spinnin' Round
18
star
76

coding_challenge-20

Building the BEST CSS ANIMATION IN THE WORLD!!
17
star
77

coding_challenge-32

Build your own version of the Keiko Corp Website!
17
star
78

coding_challenge-40

21 day coding adventure
16
star
79

coding_challenge-21

A real life interview question from Google
15
star
80

coding_challenge-17

Artificial Intelligence and chatbots
15
star
81

coding_challenge-37

Toggle dark/light mode by clapping your hands
15
star
82

worldcup-2018

This project fetches data from a JSON file which contains all the worldcup 2018 details.
JavaScript
15
star
83

coding_challenge-29

Escape From Jurassic
13
star
84

breads-server

Server code for Breads. Keep track of what you read online, and see what your friends are reading.
JavaScript
13
star
85

Trello-Clone

A clone of trello, mimicking its basic functionality.
JavaScript
12
star
86

ZtM-Workouts

A project with a variety of exercises that will help you learn development.
JavaScript
12
star
87

starwars-spaceships

JavaScript
12
star
88

drum-root-api

An Express REST API service for Creating and Sharing Drum Loops
JavaScript
12
star
89

Coding_Challenge-5

Build an event page for a real company!
11
star
90

Coding_Challenge-7

It's time for you to build your own snake game
10
star
91

litter-finder

An app to find litter using community submitted geotagged images. The submitted areas are then tracked as to whether they have been cleaned up or not. There should be a leaderboard of submissions and the overall number of submitted images displayed.
HTML
9
star
92

house-organiser

"Registers the amount and type of items that you have and helps you reach your goal of reaching a certain number of items of your choice."
CSS
8
star
93

ascii-art-2022

A ZTM Challenge for Hacktoberfest 2022, converting images into text using the 95 printable characters defined by the ASCII Standard
Python
8
star
94

mappypals_backend

Backend repo for MappyPals. An abandoned student led project. If you would like to revive this project reach out on Discord.
JavaScript
8
star
95

ztm-events

The goal of the app is to make it easier for ZTM students to find information about both the upcoming and the past ZTM events.
TypeScript
8
star
96

zero-to-mastery-captions-advanced-js

6
star
97

coding_challenge-10

Two Hacktoberfest 2018 challenges
5
star
98

CodeofConduct

Be a good human.
5
star
99

projectLive

An abandoned student led project. Reach out on Discord if you would like to revive the project!
JavaScript
5
star
100

zero-to-mastery-captions-python

4
star