Skip to content

Instantly share code, notes, and snippets.

View martin-mok's full-sized avatar

Martin martin-mok

  • /dev/null
View GitHub Profile
@martin-mok
martin-mok / uniteUnique.md
Created January 11, 2020 22:34
freecodecamp: Sorted Union

Description

Write a function that takes two or more arrays and returns a new array of unique values in the order of the original provided arrays. In other words, all values present from all arrays should be included in their original order, but with no duplicates in the final array. The unique numbers should be sorted by their original order, but the final array should not be sorted in numerical order. Check the assertion tests for examples.

Tests

@martin-mok
martin-mok / curryJS.md
Created January 11, 2020 22:25
implementation of curry function javascript
@martin-mok
martin-mok / missingLetters.md
Last active January 11, 2020 21:23
freecodecamp: Missing letters

Description

Find the missing letter in the passed letter range and return it. If all letters are present in the range, return undefined.

Tests

@martin-mok
martin-mok / spinalCase.md
Last active January 11, 2020 19:45
freecodecamp: Spinal Tap Case

Description

Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.

Tests

tests:
@martin-mok
martin-mok / objFilter.md
Created January 11, 2020 19:11
freecodecamp: Wherefore art thou

Description

Make a function that looks through an array of objects (first argument) and returns an array of all objects that have matching name and value pairs (second argument). Each name and value pair of the source object has to be present in the object from the collection if it is to be included in the returned array. For example, if the first argument is [{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], and the second argument is { last: "Capulet" }, then you must return the third object from the array (the first argument), because it contains the name and its value, that was passed on as the second argument.

Tests

@martin-mok
martin-mok / removeItems.md
Last active January 11, 2020 17:51
freecodecamp: Seek and Destroy

Description

You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.
Note: You have to use the arguments object.

Tests

@martin-mok
martin-mok / tree.md
Created January 11, 2020 17:05 — forked from hrldcpr/tree.md
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@martin-mok
martin-mok / diffArray.md
Last active January 11, 2020 17:01
freecodecamp: Diff Two Arrays

Description

Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both. In other words, return the symmetric difference of the two arrays. Note:You can return the array with its elements in any order.

Tests

@martin-mok
martin-mok / sumAll.md
Created January 10, 2020 00:54
sum all numbers in a range

Description

We'll pass you an array of two numbers. Return the sum of those two numbers plus the sum of all the numbers between them. The lowest number will not always come first. For example, sumAll([4,1]) should return 10 because sum of all the numbers between 1 and 4 (both inclusive) is 10.

Tests

@martin-mok
martin-mok / averageByReduce.md
Last active December 7, 2022 07:49
freecodecamp: Functional Programming: Use the reduce Method to Analyze Data

The variable watchList holds an array of objects with information on several movies.
Use reduce to find the average IMDB rating of the movies directed by Christopher Nolan.
Recall from prior challenges how to filter data and map over it to pull what you need.
You may need to create other variables, and return the average rating from getRating function.
Note that the rating values are saved as strings in the object and need to be converted
into numbers before they are used in any mathematical operations.

My soln:

// the global variable