Updated examples

This commit is contained in:
Angelos Chalaris
2017-12-27 16:06:16 +02:00
parent dd76327590
commit 5c2eeb3bcc
126 changed files with 187 additions and 187 deletions

View File

@ -12,5 +12,5 @@ const JSONToDate = arr => {
``` ```
```js ```js
JSONToDate(/Date(1489525200000)/) -> "14/3/2017" JSONToDate(/Date(1489525200000)/) // "14/3/2017"
``` ```

View File

@ -10,5 +10,5 @@ const JSONToFile = (obj, filename) => fs.writeFile(`${filename}.json`, JSON.stri
``` ```
```js ```js
JSONToFile({test: "is passed"}, 'testJsonFile') -> writes the object to 'testJsonFile.json' JSONToFile({test: "is passed"}, 'testJsonFile') // writes the object to 'testJsonFile.json'
``` ```

View File

@ -9,5 +9,5 @@ const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6
``` ```
```js ```js
RGBToHex(255, 165, 1) -> 'ffa501' RGBToHex(255, 165, 1) // 'ffa501'
``` ```

View File

@ -12,5 +12,5 @@ const UUIDGenerator = () =>
``` ```
```js ```js
UUIDGenerator() -> '7982fcfe-5721-4632-bede-6000885be57d' UUIDGenerator() // '7982fcfe-5721-4632-bede-6000885be57d'
``` ```

View File

@ -16,5 +16,5 @@ const anagrams = str => {
``` ```
```js ```js
anagrams('abc') -> ['abc','acb','bac','bca','cab','cba'] anagrams('abc') // ['abc','acb','bac','bca','cab','cba']
``` ```

View File

@ -9,5 +9,5 @@ const arrayAverage = arr => arr.reduce((acc, val) => acc + val, 0) / arr.length;
``` ```
```js ```js
arrayAverage([1,2,3]) -> 2 arrayAverage([1,2,3]) // 2
``` ```

View File

@ -12,6 +12,6 @@ const arrayGcd = arr =>{
``` ```
```js ```js
arrayGcd([1,2,3,4,5]) -> 1 arrayGcd([1,2,3,4,5]) // 1
arrayGcd([4,8,12]) -> 4 arrayGcd([4,8,12]) // 4
``` ```

View File

@ -13,6 +13,6 @@ const arrayLcm = arr =>{
``` ```
```js ```js
arrayLcm([1,2,3,4,5]) -> 60 arrayLcm([1,2,3,4,5]) // 60
arrayLcm([4,8,12]) -> 24 arrayLcm([4,8,12]) // 24
``` ```

View File

@ -9,5 +9,5 @@ const arrayMax = arr => Math.max(...arr);
``` ```
```js ```js
arrayMax([10, 1, 5]) -> 10 arrayMax([10, 1, 5]) // 10
``` ```

View File

@ -9,5 +9,5 @@ const arrayMin = arr => Math.min(...arr);
``` ```
```js ```js
arrayMin([10, 1, 5]) -> 1 arrayMin([10, 1, 5]) // 1
``` ```

View File

@ -9,5 +9,5 @@ const arraySum = arr => arr.reduce((acc, val) => acc + val, 0);
``` ```
```js ```js
arraySum([1,2,3,4]) -> 10 arraySum([1,2,3,4]) // 10
``` ```

View File

@ -10,5 +10,5 @@ const bottomVisible = () =>
``` ```
```js ```js
// bottomVisible() -> true // bottomVisible() // true
``` ```

View File

@ -11,6 +11,6 @@ const capitalize = ([first,...rest], lowerRest = false) =>
``` ```
```js ```js
capitalize('fooBar') -> 'FooBar' capitalize('fooBar') // 'FooBar'
capitalize('fooBar', true) -> 'Foobar' capitalize('fooBar', true) // 'Foobar'
``` ```

View File

@ -9,5 +9,5 @@ const capitalizeEveryWord = str => str.replace(/\b[a-z]/g, char => char.toUpperC
``` ```
```js ```js
capitalizeEveryWord('hello world!') -> 'Hello World!' capitalizeEveryWord('hello world!') // 'Hello World!'
``` ```

View File

@ -12,5 +12,5 @@ const chunk = (arr, size) =>
``` ```
```js ```js
chunk([1,2,3,4,5], 2) -> [[1,2],[3,4],[5]] chunk([1,2,3,4,5], 2) // [[1,2],[3,4],[5]]
``` ```

View File

@ -14,7 +14,7 @@ const clampNumber = (num, lower, upper) => {
``` ```
```js ```js
clampNumber(2, 3, 5) -> 3 clampNumber(2, 3, 5) // 3
clampNumber(1, -1, -5) -> -1 clampNumber(1, -1, -5) // -1
clampNumber(3, 2, 4) -> 3 clampNumber(3, 2, 4) // 3
``` ```

View File

@ -9,5 +9,5 @@ const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_))
``` ```
```js ```js
coalesce(null,undefined,"",NaN, "Waldo") -> "" coalesce(null,undefined,"",NaN, "Waldo") // ""
``` ```

View File

@ -9,6 +9,6 @@ const collatz = n => (n % 2 == 0) ? (n / 2) : (3 * n + 1);
``` ```
```js ```js
collatz(8) -> 4 collatz(8) // 4
collatz(5) -> 16 collatz(5) // 16
``` ```

View File

@ -9,5 +9,5 @@ const compact = arr => arr.filter(Boolean);
``` ```
```js ```js
compact([0, 1, false, 2, '', 3, 'a', 'e'*23, NaN, 's', 34]) -> [ 1, 2, 3, 'a', 's', 34 ] compact([0, 1, false, 2, '', 3, 'a', 'e'*23, NaN, 's', 34]) // [ 1, 2, 3, 'a', 's', 34 ]
``` ```

View File

@ -13,5 +13,5 @@ const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
const add5 = x => x + 5 const add5 = x => x + 5
const multiply = (x, y) => x * y const multiply = (x, y) => x * y
const multiplyAndAdd5 = compose(add5, multiply) const multiplyAndAdd5 = compose(add5, multiply)
multiplyAndAdd5(5, 2) -> 15 multiplyAndAdd5(5, 2) // 15
``` ```

View File

@ -9,5 +9,5 @@ const countOccurrences = (arr, value) => arr.reduce((a, v) => v === value ? a +
``` ```
```js ```js
countOccurrences([1,1,2,1,2,3], 1) -> 3 countOccurrences([1,1,2,1,2,3], 1) // 3
``` ```

View File

@ -9,6 +9,6 @@ const countVowels = str => (str.match(/[aeiou]/ig) || []).length;
``` ```
```js ```js
countVowels('foobar') -> 3 countVowels('foobar') // 3
countVowels('gym') -> 0 countVowels('gym') // 0
``` ```

View File

@ -9,5 +9,5 @@ const currentURL = () => window.location.href;
``` ```
```js ```js
currentUrl() -> 'https://google.com' currentUrl() // 'https://google.com'
``` ```

View File

@ -15,6 +15,6 @@ const curry = (fn, arity = fn.length, ...args) =>
``` ```
```js ```js
curry(Math.pow)(2)(10) -> 1024 curry(Math.pow)(2)(10) // 1024
curry(Math.min, 3)(10)(50)(2) -> 2 curry(Math.min, 3)(10)(50)(2) // 2
``` ```

View File

@ -11,5 +11,5 @@ const deepFlatten = arr => [].concat(...arr.map(v => Array.isArray(v) ? deepFlat
``` ```
```js ```js
deepFlatten([1,[2],[[3],4],5]) -> [1,2,3,4,5] deepFlatten([1,[2],[[3],4],5]) // [1,2,3,4,5]
``` ```

View File

@ -9,6 +9,6 @@ const detectDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobi
``` ```
```js ```js
detectDeviceType() -> "Mobile" detectDeviceType() // "Mobile"
detectDeviceType() -> "Desktop" detectDeviceType() // "Desktop"
``` ```

View File

@ -9,5 +9,5 @@ const difference = (a, b) => { const s = new Set(b); return a.filter(x => !s.has
``` ```
```js ```js
difference([1,2,3], [1,2,4]) -> [3] difference([1,2,3], [1,2,4]) // [3]
``` ```

View File

@ -9,5 +9,5 @@ const differenceWith = (arr, val, comp) => arr.filter(a => !val.find(b => comp(a
``` ```
```js ```js
differenceWith([1, 1.2, 1.5, 3], [1.9, 3], (a,b) => Math.round(a) == Math.round(b)) -> [1, 1.2] differenceWith([1, 1.2, 1.5, 3], [1.9, 3], (a,b) => Math.round(a) == Math.round(b)) // [1, 1.2]
``` ```

View File

@ -10,5 +10,5 @@ const digitize = n => [...''+n].map(i => parseInt(i));
``` ```
```js ```js
differenceWith([1, 1.2, 1.5, 3], [1.9, 3], (a,b) => Math.round(a) == Math.round(b)) -> [1, 1.2] differenceWith([1, 1.2, 1.5, 3], [1.9, 3], (a,b) => Math.round(a) == Math.round(b)) // [1, 1.2]
``` ```

View File

@ -9,5 +9,5 @@ const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
``` ```
```js ```js
distance(1,1, 2,3) -> 2.23606797749979 distance(1,1, 2,3) // 2.23606797749979
``` ```

View File

@ -9,5 +9,5 @@ const distinctValuesOfArray = arr => [...new Set(arr)];
``` ```
```js ```js
distinctValuesOfArray([1,2,2,3,4,4,5]) -> [1,2,3,4,5] distinctValuesOfArray([1,2,2,3,4,4,5]) // [1,2,3,4,5]
``` ```

View File

@ -13,5 +13,5 @@ const dropElements = (arr, func) => {
``` ```
```js ```js
dropElements([1, 2, 3, 4], n => n >= 3) -> [3,4] dropElements([1, 2, 3, 4], n => n >= 3) // [3,4]
``` ```

View File

@ -9,7 +9,7 @@ const dropRight = (arr, n = 1) => arr.slice(0, -n);
``` ```
```js ```js
dropRight([1,2,3]) -> [1,2] dropRight([1,2,3]) // [1,2]
dropRight([1,2,3], 2) -> [1] dropRight([1,2,3], 2) // [1]
dropRight([1,2,3], 42) -> [] dropRight([1,2,3], 42) // []
``` ```

View File

@ -20,6 +20,6 @@ const elementIsVisibleInViewport = (el, partiallyVisible = false) => {
```js ```js
// e.g. 100x100 viewport and a 10x10px element at position {top: -1, left: 0, bottom: 9, right: 10} // e.g. 100x100 viewport and a 10x10px element at position {top: -1, left: 0, bottom: 9, right: 10}
elementIsVisibleInViewport(el) -> false // (not fully visible) elementIsVisibleInViewport(el) // false // (not fully visible)
elementIsVisibleInViewport(el, true) -> true // (partially visible) elementIsVisibleInViewport(el, true) // true // (partially visible)
``` ```

View File

@ -9,5 +9,5 @@ const escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
``` ```
```js ```js
escapeRegExp('(test)') -> \\(test\\) escapeRegExp('(test)') // \\(test\\)
``` ```

View File

@ -9,5 +9,5 @@ const everyNth = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1);
``` ```
```js ```js
everyNth([1,2,3,4,5,6], 2) -> [ 2, 4, 6 ] everyNth([1,2,3,4,5,6], 2) // [ 2, 4, 6 ]
``` ```

View File

@ -10,6 +10,6 @@ const extendHex = shortHex =>
``` ```
```js ```js
extendHex('#03f') -> '#0033ff' extendHex('#03f') // '#0033ff'
extendHex('05a') -> '#0055aa' extendHex('05a') // '#0055aa'
``` ```

View File

@ -14,5 +14,5 @@ const factorial = n =>
``` ```
```js ```js
factorial(6) -> 720 factorial(6) // 720
``` ```

View File

@ -11,5 +11,5 @@ const fibonacci = n =>
``` ```
```js ```js
factorial(6) -> 720 factorial(6) // 720
``` ```

View File

@ -10,5 +10,5 @@ const fibonacciCountUntilNum = num =>
``` ```
```js ```js
fibonacciCountUntilNum(10) -> 7 fibonacciCountUntilNum(10) // 7
``` ```

View File

@ -14,5 +14,5 @@ const fibonacciUntilNum = num => {
``` ```
```js ```js
fibonacciCountUntilNum(10) -> 7 fibonacciCountUntilNum(10) // 7
``` ```

View File

@ -9,5 +9,5 @@ const filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexO
``` ```
```js ```js
filterNonUnique([1,2,2,3,4,4,5]) -> [1,3,5] filterNonUnique([1,2,2,3,4,4,5]) // [1,3,5]
``` ```

View File

@ -9,5 +9,5 @@ const flatten = arr => [ ].concat( ...arr );
``` ```
```js ```js
flatten([1,[2],3,4]) -> [1,2,3,4] flatten([1,[2],3,4]) // [1,2,3,4]
``` ```

View File

@ -14,5 +14,5 @@ const flattenDepth = (arr, depth = 1) =>
``` ```
```js ```js
flatten([1,[2],3,4]) -> [1,2,3,4] flatten([1,[2],3,4]) // [1,2,3,4]
``` ```

View File

@ -12,7 +12,7 @@ const fromCamelCase = (str, separator = '_') =>
``` ```
```js ```js
fromCamelCase('someDatabaseFieldName', ' ') -> 'some database field name' fromCamelCase('someDatabaseFieldName', ' ') // 'some database field name'
fromCamelCase('someLabelThatNeedsToBeCamelized', '-') -> 'some-label-that-needs-to-be-camelized' fromCamelCase('someLabelThatNeedsToBeCamelized', '-') // 'some-label-that-needs-to-be-camelized'
fromCamelCase('someJavascriptProperty', '_') -> 'some_javascript_property' fromCamelCase('someJavascriptProperty', '_') // 'some_javascript_property'
``` ```

View File

@ -9,5 +9,5 @@ const functionName = fn => (console.debug(fn.name), fn);
``` ```
```js ```js
functionName(Math.max) -> max (logged in debug channel of console) functionName(Math.max) // max (logged in debug channel of console)
``` ```

View File

@ -11,5 +11,5 @@ const gcd = (x, y) => !y ? x : gcd(y, x % y);
``` ```
```js ```js
gcd (8, 36) -> 4 gcd (8, 36) // 4
``` ```

View File

@ -9,5 +9,5 @@ const getDaysDiffBetweenDates = (dateInitial, dateFinal) => (dateFinal - dateIni
``` ```
```js ```js
getDaysDiffBetweenDates(new Date("2017-12-13"), new Date("2017-12-22")) -> 9 getDaysDiffBetweenDates(new Date("2017-12-13"), new Date("2017-12-22")) // 9
``` ```

View File

@ -12,5 +12,5 @@ const getScrollPosition = (el = window) =>
``` ```
```js ```js
getScrollPosition() -> {x: 0, y: 200} getScrollPosition() // {x: 0, y: 200}
``` ```

View File

@ -10,5 +10,5 @@ const getType = v =>
``` ```
```js ```js
getType(new Set([1,2,3])) -> "set" getType(new Set([1,2,3])) // "set"
``` ```

View File

@ -13,5 +13,5 @@ const getURLParameters = url =>
``` ```
```js ```js
getURLParameters('http://url.com/page?name=Adam&surname=Smith') -> {name: 'Adam', surname: 'Smith'} getURLParameters('http://url.com/page?name=Adam&surname=Smith') // {name: 'Adam', surname: 'Smith'}
``` ```

View File

@ -12,6 +12,6 @@ const groupBy = (arr, func) =>
``` ```
```js ```js
groupBy([6.1, 4.2, 6.3], Math.floor) -> {4: [4.2], 6: [6.1, 6.3]} groupBy([6.1, 4.2, 6.3], Math.floor) // {4: [4.2], 6: [6.1, 6.3]}
groupBy(['one', 'two', 'three'], 'length') -> {3: ['one', 'two'], 5: ['three']} groupBy(['one', 'two', 'three'], 'length') // {3: ['one', 'two'], 5: ['three']}
``` ```

View File

@ -11,5 +11,5 @@ const hammingDistance = (num1, num2) =>
``` ```
```js ```js
hammingDistance(2,3) -> 1 hammingDistance(2,3) // 1
``` ```

View File

@ -9,5 +9,5 @@ const head = arr => arr[0];
``` ```
```js ```js
head([1,2,3]) -> 1 head([1,2,3]) // 1
``` ```

View File

@ -19,7 +19,7 @@ const hexToRGB = hex => {
``` ```
```js ```js
hexToRGB('#27ae60ff') -> 'rgba(39, 174, 96, 255)' hexToRGB('#27ae60ff') // 'rgba(39, 174, 96, 255)'
hexToRGB('27ae60') -> 'rgb(39, 174, 96)' hexToRGB('27ae60') // 'rgb(39, 174, 96)'
hexToRGB('#fff') -> 'rgb(255, 255, 255)' hexToRGB('#fff') // 'rgb(255, 255, 255)'
``` ```

View File

@ -13,8 +13,8 @@ const inRange = (n, start, end=null) => {
``` ```
```js ```js
inRange(3, 2, 5) -> true inRange(3, 2, 5) // true
inRange(3, 4) -> true inRange(3, 4) // true
inRange(2, 3, 5) -> false inRange(2, 3, 5) // false
inrange(3, 2) -> false inrange(3, 2) // false
``` ```

View File

@ -9,5 +9,5 @@ const initial = arr => arr.slice(0, -1);
``` ```
```js ```js
initial([1,2,3]) -> [1,2] initial([1,2,3]) // [1,2]
``` ```

View File

@ -9,5 +9,5 @@ const initialize2DArray = (w, h, val = null) => Array(h).fill().map(() => Array(
``` ```
```js ```js
initialize2DArray(2, 2, 0) -> [[0,0], [0,0]] initialize2DArray(2, 2, 0) // [[0,0], [0,0]]
``` ```

View File

@ -11,6 +11,6 @@ const initializeArrayWithRange = (end, start = 0) =>
``` ```
```js ```js
initializeArrayWithRange(5) -> [0,1,2,3,4,5] initializeArrayWithRange(5) // [0,1,2,3,4,5]
initializeArrayWithRange(7, 3) -> [3,4,5,6,7] initializeArrayWithRange(7, 3) // [3,4,5,6,7]
``` ```

View File

@ -10,5 +10,5 @@ const initializeArrayWithValues = (n, value = 0) => Array(n).fill(value);
``` ```
```js ```js
initializeArrayWithValues(5, 2) -> [2,2,2,2,2] initializeArrayWithValues(5, 2) // [2,2,2,2,2]
``` ```

View File

@ -9,5 +9,5 @@ const intersection = (a, b) => { const s = new Set(b); return a.filter(x => s.ha
``` ```
```js ```js
intersection([1,2,3], [4,3,2]) -> [2,3] intersection([1,2,3], [4,3,2]) // [2,3]
``` ```

View File

@ -10,7 +10,7 @@ const isArmstrongNumber = digits =>
``` ```
```js ```js
isArmstrongNumber(1634) -> true isArmstrongNumber(1634) // true
isArmstrongNumber(371) -> true isArmstrongNumber(371) // true
isArmstrongNumber(56) -> false isArmstrongNumber(56) // false
``` ```

View File

@ -9,6 +9,6 @@ const isArray = val => !!val && Array.isArray(val);
``` ```
```js ```js
isArray(null) -> false isArray(null) // false
isArray([1]) -> true isArray([1]) // true
``` ```

View File

@ -9,6 +9,6 @@ const isBoolean = val => typeof val === 'boolean';
``` ```
```js ```js
isBoolean(null) -> false isBoolean(null) // false
isBoolean(false) -> true isBoolean(false) // true
``` ```

View File

@ -9,5 +9,5 @@ const isDivisible = (dividend, divisor) => dividend % divisor === 0;
``` ```
```js ```js
isDivisible(6,3) -> true isDivisible(6,3) // true
``` ```

View File

@ -10,5 +10,5 @@ const isEven = num => num % 2 === 0;
``` ```
```js ```js
isEven(3) -> false isEven(3) // false
``` ```

View File

@ -9,6 +9,6 @@ const isFunction = val => val && typeof val === 'function';
``` ```
```js ```js
isFunction('x') -> false isFunction('x') // false
isFunction(x => x) -> true isFunction(x => x) // true
``` ```

View File

@ -9,6 +9,6 @@ const isNumber = val => typeof val === 'number';
``` ```
```js ```js
isNumber('1') -> false isNumber('1') // false
isNumber(1) -> true isNumber(1) // true
``` ```

View File

@ -14,6 +14,6 @@ const isPrime = num => {
``` ```
```js ```js
isPrime(11) -> true isPrime(11) // true
isPrime(12) -> false isPrime(12) // false
``` ```

View File

@ -9,6 +9,6 @@ const isString = val => typeof val === 'string';
``` ```
```js ```js
isString(10) -> false isString(10) // false
isString('10') -> true isString('10') // true
``` ```

View File

@ -9,6 +9,6 @@ const isSymbol = val => typeof val === 'symbol';
``` ```
```js ```js
isSymbol('x') -> false isSymbol('x') // false
isSymbol(Symbol('x')) -> true isSymbol(Symbol('x')) // true
``` ```

View File

@ -9,5 +9,5 @@ const last = arr => arr[arr.length - 1];
``` ```
```js ```js
last([1,2,3]) -> 3 last([1,2,3]) // 3
``` ```

View File

@ -13,5 +13,5 @@ const lcm = (x,y) => {
``` ```
```js ```js
lcm(12,7) -> 84 lcm(12,7) // 84
``` ```

View File

@ -13,6 +13,6 @@ const median = arr => {
``` ```
```js ```js
median([5,6,50,1,-5]) -> 5 median([5,6,50,1,-5]) // 5
median([0,10,-2,7]) -> 3.5 median([0,10,-2,7]) // 3.5
``` ```

View File

@ -9,6 +9,6 @@ const negate = func => (...args) => !func(...args);
``` ```
```js ```js
filter([1, 2, 3, 4, 5, 6], negate(isEven)) -> [1, 3, 5] filter([1, 2, 3, 4, 5, 6], negate(isEven)) // [1, 3, 5]
negate(isOdd)(1) -> false negate(isOdd)(1) // false
``` ```

View File

@ -11,6 +11,6 @@ const nthElement = (arr, n=0) => (n>0? arr.slice(n,n+1) : arr.slice(n))[0];
``` ```
```js ```js
nthElement(['a','b','c'],1) -> 'b' nthElement(['a','b','c'],1) // 'b'
nthElement(['a','b','b'],-3) -> 'a' nthElement(['a','b','b'],-3) // 'a'
``` ```

View File

@ -9,5 +9,5 @@ const objectFromPairs = arr => arr.reduce((a, v) => (a[v[0]] = v[1], a), {});
``` ```
```js ```js
objectFromPairs([['a',1],['b',2]]) -> {a: 1, b: 2} objectFromPairs([['a',1],['b',2]]) // {a: 1, b: 2}
``` ```

View File

@ -9,5 +9,5 @@ const objectToPairs = obj => Object.keys(obj).map(k => [k, obj[k]]);
``` ```
```js ```js
objectToPairs({a: 1, b: 2}) -> [['a',1],['b',2]]) objectToPairs({a: 1, b: 2}) // [['a',1],['b',2]])
``` ```

View File

@ -21,6 +21,6 @@ const orderBy = (arr, props, orders) =>
```js ```js
const users = [{ 'name': 'fred', 'age': 48 },{ 'name': 'barney', 'age': 36 }, const users = [{ 'name': 'fred', 'age': 48 },{ 'name': 'barney', 'age': 36 },
{ 'name': 'fred', 'age': 40 },{ 'name': 'barney', 'age': 34 }]; { 'name': 'fred', 'age': 40 },{ 'name': 'barney', 'age': 34 }];
orderby(users, ['name', 'age'], ['asc', 'desc']) -> [{name: 'barney', age: 36}, {name: 'barney', age: 34}, {name: 'fred', age: 48}, {name: 'fred', age: 40}] orderby(users, ['name', 'age'], ['asc', 'desc']) // [{name: 'barney', age: 36}, {name: 'barney', age: 34}, {name: 'fred', age: 48}, {name: 'fred', age: 40}]
orderby(users, ['name', 'age']) -> [{name: 'barney', age: 34}, {name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred', age: 48}] orderby(users, ['name', 'age']) // [{name: 'barney', age: 34}, {name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred', age: 48}]
``` ```

View File

@ -13,5 +13,5 @@ const palindrome = str => {
``` ```
```js ```js
palindrome('taco cat') -> true palindrome('taco cat') // true
``` ```

View File

@ -10,5 +10,5 @@ const percentile = (arr, val) =>
``` ```
```js ```js
percentile([1,2,3,4,5,6,7,8,9,10], 6) -> 55 percentile([1,2,3,4,5,6,7,8,9,10], 6) // 55
``` ```

View File

@ -10,5 +10,5 @@ const pick = (obj, arr) =>
``` ```
```js ```js
pick({ 'a': 1, 'b': '2', 'c': 3 }, ['a', 'c']) -> { 'a': 1, 'c': 3 } pick({ 'a': 1, 'b': '2', 'c': 3 }, ['a', 'c']) // { 'a': 1, 'c': 3 }
``` ```

View File

@ -13,5 +13,5 @@ const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)
const add5 = x => x + 5 const add5 = x => x + 5
const multiply = (x, y) => x * y const multiply = (x, y) => x * y
const multiplyAndAdd5 = pipeFunctions(multiply, add5) const multiplyAndAdd5 = pipeFunctions(multiply, add5)
multiplyAndAdd5(5, 2) -> 15 multiplyAndAdd5(5, 2) // 15
``` ```

View File

@ -10,5 +10,5 @@ const powerset = arr =>
``` ```
```js ```js
powerset([1,2]) -> [[], [1], [2], [2,1]] powerset([1,2]) // [[], [1], [2], [2,1]]
``` ```

View File

@ -15,5 +15,5 @@ const primes = num => {
``` ```
```js ```js
primes(10) -> [2,3,5,7] primes(10) // [2,3,5,7]
``` ```

View File

@ -18,5 +18,5 @@ const promisify = func =>
```js ```js
const delay = promisify((d, cb) => setTimeout(cb, d)) const delay = promisify((d, cb) => setTimeout(cb, d))
delay(2000).then(() => console.log('Hi!')) -> // Promise resolves after 2s delay(2000).then(() => console.log('Hi!')) // // Promise resolves after 2s
``` ```

View File

@ -19,9 +19,9 @@ const pull = (arr, ...args) => {
```js ```js
let myArray1 = ['a', 'b', 'c', 'a', 'b', 'c']; let myArray1 = ['a', 'b', 'c', 'a', 'b', 'c'];
pull(myArray1, 'a', 'c'); pull(myArray1, 'a', 'c');
console.log(myArray1) -> [ 'b', 'b' ] console.log(myArray1) // [ 'b', 'b' ]
let myArray2 = ['a', 'b', 'c', 'a', 'b', 'c']; let myArray2 = ['a', 'b', 'c', 'a', 'b', 'c'];
pull(myArray2, ['a', 'c']); pull(myArray2, ['a', 'c']);
console.log(myArray2) -> [ 'b', 'b' ] console.log(myArray2) // [ 'b', 'b' ]
``` ```

View File

@ -21,6 +21,6 @@ const pullAtIndex = (arr, pullArr) => {
let myArray = ['a', 'b', 'c', 'd']; let myArray = ['a', 'b', 'c', 'd'];
let pulled = pullAtIndex(myArray, [1, 3]); let pulled = pullAtIndex(myArray, [1, 3]);
console.log(myArray); -> [ 'a', 'c' ] console.log(myArray); // [ 'a', 'c' ]
console.log(pulled); -> [ 'b', 'd' ] console.log(pulled); // [ 'b', 'd' ]
``` ```

View File

@ -20,6 +20,6 @@ const pullAtValue = (arr, pullArr) => {
```js ```js
let myArray = ['a', 'b', 'c', 'd']; let myArray = ['a', 'b', 'c', 'd'];
let pulled = pullAtValue(myArray, ['b', 'd']); let pulled = pullAtValue(myArray, ['b', 'd']);
console.log(myArray); -> [ 'a', 'c' ] console.log(myArray); // [ 'a', 'c' ]
console.log(pulled); -> [ 'b', 'd' ] console.log(pulled); // [ 'b', 'd' ]
``` ```

View File

@ -9,7 +9,7 @@ const randomHexColorCode = () => '#'+(Math.random()*0xFFFFFF<<0).toString(16);
``` ```
```js ```js
randomHexColorCode() -> "#e34155" randomHexColorCode() // "#e34155"
randomHexColorCode() -> "#fd73a6" randomHexColorCode() // "#fd73a6"
randomHexColorCode() -> "#4144c6" randomHexColorCode() // "#4144c6"
``` ```

View File

@ -9,5 +9,5 @@ const randomIntegerInRange = (min, max) => Math.floor(Math.random() * (max - min
``` ```
```js ```js
randomIntegerInRange(0, 5) -> 2 randomIntegerInRange(0, 5) // 2
``` ```

View File

@ -9,5 +9,5 @@ const randomNumberInRange = (min, max) => Math.random() * (max - min) + min;
``` ```
```js ```js
randomNumberInRange(2,10) -> 6.0211363285087005 randomNumberInRange(2,10) // 6.0211363285087005
``` ```

View File

@ -18,5 +18,5 @@ contents of test.txt :
line3 line3
___________________________ ___________________________
let arr = readFileLines('test.txt') let arr = readFileLines('test.txt')
console.log(arr) // -> ['line1', 'line2', 'line3'] console.log(arr) // // ['line1', 'line2', 'line3']
``` ```

View File

@ -14,5 +14,5 @@ const remove = (arr, func) =>
``` ```
```js ```js
remove([1, 2, 3, 4], n => n % 2 == 0) -> [2, 4] remove([1, 2, 3, 4], n => n % 2 == 0) // [2, 4]
``` ```

View File

@ -11,6 +11,6 @@ const repeatString = (str="",num=2) => {
``` ```
```js ```js
repeatString("abc",3) -> 'abcabcabc' repeatString("abc",3) // 'abcabcabc'
repeatString("abc") -> 'abcabc' repeatString("abc") // 'abcabc'
``` ```

View File

@ -10,5 +10,5 @@ const reverseString = str => str.split('').reverse().join('');
``` ```
```js ```js
reverseString('foobar') -> 'raboof' reverseString('foobar') // 'raboof'
``` ```

View File

@ -10,5 +10,5 @@ const round = (n, decimals=0) => Number(`${Math.round(`${n}e${decimals}`)}e-${de
``` ```
```js ```js
round(1.005, 2) -> 1.01 round(1.005, 2) // 1.01
``` ```

View File

@ -10,5 +10,5 @@ const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.r
```js ```js
const delay = (d) => new Promise(r => setTimeout(r, d)) const delay = (d) => new Promise(r => setTimeout(r, d))
runPromisesInSeries([() => delay(1000), () => delay(2000)]) -> //executes each promise sequentially, taking a total of 3 seconds to complete runPromisesInSeries([() => delay(1000), () => delay(2000)]) // //executes each promise sequentially, taking a total of 3 seconds to complete
``` ```

View File

@ -10,5 +10,5 @@ const sample = arr => arr[Math.floor(Math.random() * arr.length)];
``` ```
```js ```js
sample([3, 7, 9, 11]) -> 9 sample([3, 7, 9, 11]) // 9
``` ```

View File

@ -11,5 +11,5 @@ const select = (from, selector) =>
```js ```js
const obj = {selector: {to: {val: 'val to select'}}}; const obj = {selector: {to: {val: 'val to select'}}};
select(obj, 'selector.to.val'); -> 'val to select' select(obj, 'selector.to.val'); // 'val to select'
``` ```

Some files were not shown because too many files have changed in this diff Show More