Updated examples
This commit is contained in:
@ -12,5 +12,5 @@ const JSONToDate = arr => {
|
||||
```
|
||||
|
||||
```js
|
||||
JSONToDate(/Date(1489525200000)/) -> "14/3/2017"
|
||||
JSONToDate(/Date(1489525200000)/) // "14/3/2017"
|
||||
```
|
||||
|
||||
@ -10,5 +10,5 @@ const JSONToFile = (obj, filename) => fs.writeFile(`${filename}.json`, JSON.stri
|
||||
```
|
||||
|
||||
```js
|
||||
JSONToFile({test: "is passed"}, 'testJsonFile') -> writes the object to 'testJsonFile.json'
|
||||
JSONToFile({test: "is passed"}, 'testJsonFile') // writes the object to 'testJsonFile.json'
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6
|
||||
```
|
||||
|
||||
```js
|
||||
RGBToHex(255, 165, 1) -> 'ffa501'
|
||||
RGBToHex(255, 165, 1) // 'ffa501'
|
||||
```
|
||||
|
||||
@ -12,5 +12,5 @@ const UUIDGenerator = () =>
|
||||
```
|
||||
|
||||
```js
|
||||
UUIDGenerator() -> '7982fcfe-5721-4632-bede-6000885be57d'
|
||||
UUIDGenerator() // '7982fcfe-5721-4632-bede-6000885be57d'
|
||||
```
|
||||
|
||||
@ -16,5 +16,5 @@ const anagrams = str => {
|
||||
```
|
||||
|
||||
```js
|
||||
anagrams('abc') -> ['abc','acb','bac','bca','cab','cba']
|
||||
anagrams('abc') // ['abc','acb','bac','bca','cab','cba']
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const arrayAverage = arr => arr.reduce((acc, val) => acc + val, 0) / arr.length;
|
||||
```
|
||||
|
||||
```js
|
||||
arrayAverage([1,2,3]) -> 2
|
||||
arrayAverage([1,2,3]) // 2
|
||||
```
|
||||
|
||||
@ -12,6 +12,6 @@ const arrayGcd = arr =>{
|
||||
```
|
||||
|
||||
```js
|
||||
arrayGcd([1,2,3,4,5]) -> 1
|
||||
arrayGcd([4,8,12]) -> 4
|
||||
arrayGcd([1,2,3,4,5]) // 1
|
||||
arrayGcd([4,8,12]) // 4
|
||||
```
|
||||
|
||||
@ -13,6 +13,6 @@ const arrayLcm = arr =>{
|
||||
```
|
||||
|
||||
```js
|
||||
arrayLcm([1,2,3,4,5]) -> 60
|
||||
arrayLcm([4,8,12]) -> 24
|
||||
arrayLcm([1,2,3,4,5]) // 60
|
||||
arrayLcm([4,8,12]) // 24
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const arrayMax = arr => Math.max(...arr);
|
||||
```
|
||||
|
||||
```js
|
||||
arrayMax([10, 1, 5]) -> 10
|
||||
arrayMax([10, 1, 5]) // 10
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const arrayMin = arr => Math.min(...arr);
|
||||
```
|
||||
|
||||
```js
|
||||
arrayMin([10, 1, 5]) -> 1
|
||||
arrayMin([10, 1, 5]) // 1
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const arraySum = arr => arr.reduce((acc, val) => acc + val, 0);
|
||||
```
|
||||
|
||||
```js
|
||||
arraySum([1,2,3,4]) -> 10
|
||||
arraySum([1,2,3,4]) // 10
|
||||
```
|
||||
|
||||
@ -10,5 +10,5 @@ const bottomVisible = () =>
|
||||
```
|
||||
|
||||
```js
|
||||
// bottomVisible() -> true
|
||||
// bottomVisible() // true
|
||||
```
|
||||
|
||||
@ -11,6 +11,6 @@ const capitalize = ([first,...rest], lowerRest = false) =>
|
||||
```
|
||||
|
||||
```js
|
||||
capitalize('fooBar') -> 'FooBar'
|
||||
capitalize('fooBar', true) -> 'Foobar'
|
||||
capitalize('fooBar') // 'FooBar'
|
||||
capitalize('fooBar', true) // 'Foobar'
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const capitalizeEveryWord = str => str.replace(/\b[a-z]/g, char => char.toUpperC
|
||||
```
|
||||
|
||||
```js
|
||||
capitalizeEveryWord('hello world!') -> 'Hello World!'
|
||||
capitalizeEveryWord('hello world!') // 'Hello World!'
|
||||
```
|
||||
|
||||
@ -12,5 +12,5 @@ const chunk = (arr, size) =>
|
||||
```
|
||||
|
||||
```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]]
|
||||
```
|
||||
|
||||
@ -14,7 +14,7 @@ const clampNumber = (num, lower, upper) => {
|
||||
```
|
||||
|
||||
```js
|
||||
clampNumber(2, 3, 5) -> 3
|
||||
clampNumber(1, -1, -5) -> -1
|
||||
clampNumber(3, 2, 4) -> 3
|
||||
clampNumber(2, 3, 5) // 3
|
||||
clampNumber(1, -1, -5) // -1
|
||||
clampNumber(3, 2, 4) // 3
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_))
|
||||
```
|
||||
|
||||
```js
|
||||
coalesce(null,undefined,"",NaN, "Waldo") -> ""
|
||||
coalesce(null,undefined,"",NaN, "Waldo") // ""
|
||||
```
|
||||
|
||||
@ -9,6 +9,6 @@ const collatz = n => (n % 2 == 0) ? (n / 2) : (3 * n + 1);
|
||||
```
|
||||
|
||||
```js
|
||||
collatz(8) -> 4
|
||||
collatz(5) -> 16
|
||||
collatz(8) // 4
|
||||
collatz(5) // 16
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const compact = arr => arr.filter(Boolean);
|
||||
```
|
||||
|
||||
```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 ]
|
||||
```
|
||||
|
||||
@ -13,5 +13,5 @@ const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
|
||||
const add5 = x => x + 5
|
||||
const multiply = (x, y) => x * y
|
||||
const multiplyAndAdd5 = compose(add5, multiply)
|
||||
multiplyAndAdd5(5, 2) -> 15
|
||||
multiplyAndAdd5(5, 2) // 15
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const countOccurrences = (arr, value) => arr.reduce((a, v) => v === value ? a +
|
||||
```
|
||||
|
||||
```js
|
||||
countOccurrences([1,1,2,1,2,3], 1) -> 3
|
||||
countOccurrences([1,1,2,1,2,3], 1) // 3
|
||||
```
|
||||
|
||||
@ -9,6 +9,6 @@ const countVowels = str => (str.match(/[aeiou]/ig) || []).length;
|
||||
```
|
||||
|
||||
```js
|
||||
countVowels('foobar') -> 3
|
||||
countVowels('gym') -> 0
|
||||
countVowels('foobar') // 3
|
||||
countVowels('gym') // 0
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const currentURL = () => window.location.href;
|
||||
```
|
||||
|
||||
```js
|
||||
currentUrl() -> 'https://google.com'
|
||||
currentUrl() // 'https://google.com'
|
||||
```
|
||||
|
||||
@ -15,6 +15,6 @@ const curry = (fn, arity = fn.length, ...args) =>
|
||||
```
|
||||
|
||||
```js
|
||||
curry(Math.pow)(2)(10) -> 1024
|
||||
curry(Math.min, 3)(10)(50)(2) -> 2
|
||||
curry(Math.pow)(2)(10) // 1024
|
||||
curry(Math.min, 3)(10)(50)(2) // 2
|
||||
```
|
||||
|
||||
@ -11,5 +11,5 @@ const deepFlatten = arr => [].concat(...arr.map(v => Array.isArray(v) ? deepFlat
|
||||
```
|
||||
|
||||
```js
|
||||
deepFlatten([1,[2],[[3],4],5]) -> [1,2,3,4,5]
|
||||
deepFlatten([1,[2],[[3],4],5]) // [1,2,3,4,5]
|
||||
```
|
||||
|
||||
@ -9,6 +9,6 @@ const detectDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobi
|
||||
```
|
||||
|
||||
```js
|
||||
detectDeviceType() -> "Mobile"
|
||||
detectDeviceType() -> "Desktop"
|
||||
detectDeviceType() // "Mobile"
|
||||
detectDeviceType() // "Desktop"
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const difference = (a, b) => { const s = new Set(b); return a.filter(x => !s.has
|
||||
```
|
||||
|
||||
```js
|
||||
difference([1,2,3], [1,2,4]) -> [3]
|
||||
difference([1,2,3], [1,2,4]) // [3]
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const differenceWith = (arr, val, comp) => arr.filter(a => !val.find(b => comp(a
|
||||
```
|
||||
|
||||
```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]
|
||||
```
|
||||
|
||||
@ -10,5 +10,5 @@ const digitize = n => [...''+n].map(i => parseInt(i));
|
||||
```
|
||||
|
||||
```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]
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
|
||||
```
|
||||
|
||||
```js
|
||||
distance(1,1, 2,3) -> 2.23606797749979
|
||||
distance(1,1, 2,3) // 2.23606797749979
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const distinctValuesOfArray = arr => [...new Set(arr)];
|
||||
```
|
||||
|
||||
```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]
|
||||
```
|
||||
|
||||
@ -13,5 +13,5 @@ const dropElements = (arr, func) => {
|
||||
```
|
||||
|
||||
```js
|
||||
dropElements([1, 2, 3, 4], n => n >= 3) -> [3,4]
|
||||
dropElements([1, 2, 3, 4], n => n >= 3) // [3,4]
|
||||
```
|
||||
|
||||
@ -9,7 +9,7 @@ const dropRight = (arr, n = 1) => arr.slice(0, -n);
|
||||
```
|
||||
|
||||
```js
|
||||
dropRight([1,2,3]) -> [1,2]
|
||||
dropRight([1,2,3], 2) -> [1]
|
||||
dropRight([1,2,3], 42) -> []
|
||||
dropRight([1,2,3]) // [1,2]
|
||||
dropRight([1,2,3], 2) // [1]
|
||||
dropRight([1,2,3], 42) // []
|
||||
```
|
||||
|
||||
@ -20,6 +20,6 @@ const elementIsVisibleInViewport = (el, partiallyVisible = false) => {
|
||||
|
||||
```js
|
||||
// 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, true) -> true // (partially visible)
|
||||
elementIsVisibleInViewport(el) // false // (not fully visible)
|
||||
elementIsVisibleInViewport(el, true) // true // (partially visible)
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
```
|
||||
|
||||
```js
|
||||
escapeRegExp('(test)') -> \\(test\\)
|
||||
escapeRegExp('(test)') // \\(test\\)
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const everyNth = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1);
|
||||
```
|
||||
|
||||
```js
|
||||
everyNth([1,2,3,4,5,6], 2) -> [ 2, 4, 6 ]
|
||||
everyNth([1,2,3,4,5,6], 2) // [ 2, 4, 6 ]
|
||||
```
|
||||
|
||||
@ -10,6 +10,6 @@ const extendHex = shortHex =>
|
||||
```
|
||||
|
||||
```js
|
||||
extendHex('#03f') -> '#0033ff'
|
||||
extendHex('05a') -> '#0055aa'
|
||||
extendHex('#03f') // '#0033ff'
|
||||
extendHex('05a') // '#0055aa'
|
||||
```
|
||||
|
||||
@ -14,5 +14,5 @@ const factorial = n =>
|
||||
```
|
||||
|
||||
```js
|
||||
factorial(6) -> 720
|
||||
factorial(6) // 720
|
||||
```
|
||||
|
||||
@ -11,5 +11,5 @@ const fibonacci = n =>
|
||||
```
|
||||
|
||||
```js
|
||||
factorial(6) -> 720
|
||||
factorial(6) // 720
|
||||
```
|
||||
|
||||
@ -10,5 +10,5 @@ const fibonacciCountUntilNum = num =>
|
||||
```
|
||||
|
||||
```js
|
||||
fibonacciCountUntilNum(10) -> 7
|
||||
fibonacciCountUntilNum(10) // 7
|
||||
```
|
||||
|
||||
@ -14,5 +14,5 @@ const fibonacciUntilNum = num => {
|
||||
```
|
||||
|
||||
```js
|
||||
fibonacciCountUntilNum(10) -> 7
|
||||
fibonacciCountUntilNum(10) // 7
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexO
|
||||
```
|
||||
|
||||
```js
|
||||
filterNonUnique([1,2,2,3,4,4,5]) -> [1,3,5]
|
||||
filterNonUnique([1,2,2,3,4,4,5]) // [1,3,5]
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const flatten = arr => [ ].concat( ...arr );
|
||||
```
|
||||
|
||||
```js
|
||||
flatten([1,[2],3,4]) -> [1,2,3,4]
|
||||
flatten([1,[2],3,4]) // [1,2,3,4]
|
||||
```
|
||||
|
||||
@ -14,5 +14,5 @@ const flattenDepth = (arr, depth = 1) =>
|
||||
```
|
||||
|
||||
```js
|
||||
flatten([1,[2],3,4]) -> [1,2,3,4]
|
||||
flatten([1,[2],3,4]) // [1,2,3,4]
|
||||
```
|
||||
|
||||
@ -12,7 +12,7 @@ const fromCamelCase = (str, separator = '_') =>
|
||||
```
|
||||
|
||||
```js
|
||||
fromCamelCase('someDatabaseFieldName', ' ') -> 'some database field name'
|
||||
fromCamelCase('someLabelThatNeedsToBeCamelized', '-') -> 'some-label-that-needs-to-be-camelized'
|
||||
fromCamelCase('someJavascriptProperty', '_') -> 'some_javascript_property'
|
||||
fromCamelCase('someDatabaseFieldName', ' ') // 'some database field name'
|
||||
fromCamelCase('someLabelThatNeedsToBeCamelized', '-') // 'some-label-that-needs-to-be-camelized'
|
||||
fromCamelCase('someJavascriptProperty', '_') // 'some_javascript_property'
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const functionName = fn => (console.debug(fn.name), fn);
|
||||
```
|
||||
|
||||
```js
|
||||
functionName(Math.max) -> max (logged in debug channel of console)
|
||||
functionName(Math.max) // max (logged in debug channel of console)
|
||||
```
|
||||
|
||||
@ -11,5 +11,5 @@ const gcd = (x, y) => !y ? x : gcd(y, x % y);
|
||||
```
|
||||
|
||||
```js
|
||||
gcd (8, 36) -> 4
|
||||
gcd (8, 36) // 4
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const getDaysDiffBetweenDates = (dateInitial, dateFinal) => (dateFinal - dateIni
|
||||
```
|
||||
|
||||
```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
|
||||
```
|
||||
|
||||
@ -12,5 +12,5 @@ const getScrollPosition = (el = window) =>
|
||||
```
|
||||
|
||||
```js
|
||||
getScrollPosition() -> {x: 0, y: 200}
|
||||
getScrollPosition() // {x: 0, y: 200}
|
||||
```
|
||||
|
||||
@ -10,5 +10,5 @@ const getType = v =>
|
||||
```
|
||||
|
||||
```js
|
||||
getType(new Set([1,2,3])) -> "set"
|
||||
getType(new Set([1,2,3])) // "set"
|
||||
```
|
||||
|
||||
@ -13,5 +13,5 @@ const getURLParameters = url =>
|
||||
```
|
||||
|
||||
```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'}
|
||||
```
|
||||
|
||||
@ -12,6 +12,6 @@ const groupBy = (arr, func) =>
|
||||
```
|
||||
|
||||
```js
|
||||
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([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']}
|
||||
```
|
||||
|
||||
@ -11,5 +11,5 @@ const hammingDistance = (num1, num2) =>
|
||||
```
|
||||
|
||||
```js
|
||||
hammingDistance(2,3) -> 1
|
||||
hammingDistance(2,3) // 1
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const head = arr => arr[0];
|
||||
```
|
||||
|
||||
```js
|
||||
head([1,2,3]) -> 1
|
||||
head([1,2,3]) // 1
|
||||
```
|
||||
|
||||
@ -19,7 +19,7 @@ const hexToRGB = hex => {
|
||||
```
|
||||
|
||||
```js
|
||||
hexToRGB('#27ae60ff') -> 'rgba(39, 174, 96, 255)'
|
||||
hexToRGB('27ae60') -> 'rgb(39, 174, 96)'
|
||||
hexToRGB('#fff') -> 'rgb(255, 255, 255)'
|
||||
hexToRGB('#27ae60ff') // 'rgba(39, 174, 96, 255)'
|
||||
hexToRGB('27ae60') // 'rgb(39, 174, 96)'
|
||||
hexToRGB('#fff') // 'rgb(255, 255, 255)'
|
||||
```
|
||||
|
||||
@ -13,8 +13,8 @@ const inRange = (n, start, end=null) => {
|
||||
```
|
||||
|
||||
```js
|
||||
inRange(3, 2, 5) -> true
|
||||
inRange(3, 4) -> true
|
||||
inRange(2, 3, 5) -> false
|
||||
inrange(3, 2) -> false
|
||||
inRange(3, 2, 5) // true
|
||||
inRange(3, 4) // true
|
||||
inRange(2, 3, 5) // false
|
||||
inrange(3, 2) // false
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const initial = arr => arr.slice(0, -1);
|
||||
```
|
||||
|
||||
```js
|
||||
initial([1,2,3]) -> [1,2]
|
||||
initial([1,2,3]) // [1,2]
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const initialize2DArray = (w, h, val = null) => Array(h).fill().map(() => Array(
|
||||
```
|
||||
|
||||
```js
|
||||
initialize2DArray(2, 2, 0) -> [[0,0], [0,0]]
|
||||
initialize2DArray(2, 2, 0) // [[0,0], [0,0]]
|
||||
```
|
||||
|
||||
@ -11,6 +11,6 @@ const initializeArrayWithRange = (end, start = 0) =>
|
||||
```
|
||||
|
||||
```js
|
||||
initializeArrayWithRange(5) -> [0,1,2,3,4,5]
|
||||
initializeArrayWithRange(7, 3) -> [3,4,5,6,7]
|
||||
initializeArrayWithRange(5) // [0,1,2,3,4,5]
|
||||
initializeArrayWithRange(7, 3) // [3,4,5,6,7]
|
||||
```
|
||||
|
||||
@ -10,5 +10,5 @@ const initializeArrayWithValues = (n, value = 0) => Array(n).fill(value);
|
||||
```
|
||||
|
||||
```js
|
||||
initializeArrayWithValues(5, 2) -> [2,2,2,2,2]
|
||||
initializeArrayWithValues(5, 2) // [2,2,2,2,2]
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const intersection = (a, b) => { const s = new Set(b); return a.filter(x => s.ha
|
||||
```
|
||||
|
||||
```js
|
||||
intersection([1,2,3], [4,3,2]) -> [2,3]
|
||||
intersection([1,2,3], [4,3,2]) // [2,3]
|
||||
```
|
||||
|
||||
@ -10,7 +10,7 @@ const isArmstrongNumber = digits =>
|
||||
```
|
||||
|
||||
```js
|
||||
isArmstrongNumber(1634) -> true
|
||||
isArmstrongNumber(371) -> true
|
||||
isArmstrongNumber(56) -> false
|
||||
isArmstrongNumber(1634) // true
|
||||
isArmstrongNumber(371) // true
|
||||
isArmstrongNumber(56) // false
|
||||
```
|
||||
|
||||
@ -9,6 +9,6 @@ const isArray = val => !!val && Array.isArray(val);
|
||||
```
|
||||
|
||||
```js
|
||||
isArray(null) -> false
|
||||
isArray([1]) -> true
|
||||
isArray(null) // false
|
||||
isArray([1]) // true
|
||||
```
|
||||
|
||||
@ -9,6 +9,6 @@ const isBoolean = val => typeof val === 'boolean';
|
||||
```
|
||||
|
||||
```js
|
||||
isBoolean(null) -> false
|
||||
isBoolean(false) -> true
|
||||
isBoolean(null) // false
|
||||
isBoolean(false) // true
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const isDivisible = (dividend, divisor) => dividend % divisor === 0;
|
||||
```
|
||||
|
||||
```js
|
||||
isDivisible(6,3) -> true
|
||||
isDivisible(6,3) // true
|
||||
```
|
||||
|
||||
@ -10,5 +10,5 @@ const isEven = num => num % 2 === 0;
|
||||
```
|
||||
|
||||
```js
|
||||
isEven(3) -> false
|
||||
isEven(3) // false
|
||||
```
|
||||
|
||||
@ -9,6 +9,6 @@ const isFunction = val => val && typeof val === 'function';
|
||||
```
|
||||
|
||||
```js
|
||||
isFunction('x') -> false
|
||||
isFunction(x => x) -> true
|
||||
isFunction('x') // false
|
||||
isFunction(x => x) // true
|
||||
```
|
||||
|
||||
@ -9,6 +9,6 @@ const isNumber = val => typeof val === 'number';
|
||||
```
|
||||
|
||||
```js
|
||||
isNumber('1') -> false
|
||||
isNumber(1) -> true
|
||||
isNumber('1') // false
|
||||
isNumber(1) // true
|
||||
```
|
||||
@ -14,6 +14,6 @@ const isPrime = num => {
|
||||
```
|
||||
|
||||
```js
|
||||
isPrime(11) -> true
|
||||
isPrime(12) -> false
|
||||
isPrime(11) // true
|
||||
isPrime(12) // false
|
||||
```
|
||||
|
||||
@ -9,6 +9,6 @@ const isString = val => typeof val === 'string';
|
||||
```
|
||||
|
||||
```js
|
||||
isString(10) -> false
|
||||
isString('10') -> true
|
||||
isString(10) // false
|
||||
isString('10') // true
|
||||
```
|
||||
|
||||
@ -9,6 +9,6 @@ const isSymbol = val => typeof val === 'symbol';
|
||||
```
|
||||
|
||||
```js
|
||||
isSymbol('x') -> false
|
||||
isSymbol(Symbol('x')) -> true
|
||||
isSymbol('x') // false
|
||||
isSymbol(Symbol('x')) // true
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const last = arr => arr[arr.length - 1];
|
||||
```
|
||||
|
||||
```js
|
||||
last([1,2,3]) -> 3
|
||||
last([1,2,3]) // 3
|
||||
```
|
||||
|
||||
@ -13,5 +13,5 @@ const lcm = (x,y) => {
|
||||
```
|
||||
|
||||
```js
|
||||
lcm(12,7) -> 84
|
||||
lcm(12,7) // 84
|
||||
```
|
||||
|
||||
@ -13,6 +13,6 @@ const median = arr => {
|
||||
```
|
||||
|
||||
```js
|
||||
median([5,6,50,1,-5]) -> 5
|
||||
median([0,10,-2,7]) -> 3.5
|
||||
median([5,6,50,1,-5]) // 5
|
||||
median([0,10,-2,7]) // 3.5
|
||||
```
|
||||
|
||||
@ -9,6 +9,6 @@ const negate = func => (...args) => !func(...args);
|
||||
```
|
||||
|
||||
```js
|
||||
filter([1, 2, 3, 4, 5, 6], negate(isEven)) -> [1, 3, 5]
|
||||
negate(isOdd)(1) -> false
|
||||
filter([1, 2, 3, 4, 5, 6], negate(isEven)) // [1, 3, 5]
|
||||
negate(isOdd)(1) // false
|
||||
```
|
||||
|
||||
@ -11,6 +11,6 @@ const nthElement = (arr, n=0) => (n>0? arr.slice(n,n+1) : arr.slice(n))[0];
|
||||
```
|
||||
|
||||
```js
|
||||
nthElement(['a','b','c'],1) -> 'b'
|
||||
nthElement(['a','b','b'],-3) -> 'a'
|
||||
nthElement(['a','b','c'],1) // 'b'
|
||||
nthElement(['a','b','b'],-3) // 'a'
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const objectFromPairs = arr => arr.reduce((a, v) => (a[v[0]] = v[1], a), {});
|
||||
```
|
||||
|
||||
```js
|
||||
objectFromPairs([['a',1],['b',2]]) -> {a: 1, b: 2}
|
||||
objectFromPairs([['a',1],['b',2]]) // {a: 1, b: 2}
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const objectToPairs = obj => Object.keys(obj).map(k => [k, obj[k]]);
|
||||
```
|
||||
|
||||
```js
|
||||
objectToPairs({a: 1, b: 2}) -> [['a',1],['b',2]])
|
||||
objectToPairs({a: 1, b: 2}) // [['a',1],['b',2]])
|
||||
```
|
||||
|
||||
@ -21,6 +21,6 @@ const orderBy = (arr, props, orders) =>
|
||||
```js
|
||||
const users = [{ 'name': 'fred', 'age': 48 },{ 'name': 'barney', 'age': 36 },
|
||||
{ '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']) -> [{name: 'barney', age: 34}, {name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred', age: 48}]
|
||||
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}]
|
||||
```
|
||||
|
||||
@ -13,5 +13,5 @@ const palindrome = str => {
|
||||
```
|
||||
|
||||
```js
|
||||
palindrome('taco cat') -> true
|
||||
palindrome('taco cat') // true
|
||||
```
|
||||
|
||||
@ -10,5 +10,5 @@ const percentile = (arr, val) =>
|
||||
```
|
||||
|
||||
```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
|
||||
```
|
||||
|
||||
@ -10,5 +10,5 @@ const pick = (obj, arr) =>
|
||||
```
|
||||
|
||||
```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 }
|
||||
```
|
||||
|
||||
@ -13,5 +13,5 @@ const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)
|
||||
const add5 = x => x + 5
|
||||
const multiply = (x, y) => x * y
|
||||
const multiplyAndAdd5 = pipeFunctions(multiply, add5)
|
||||
multiplyAndAdd5(5, 2) -> 15
|
||||
multiplyAndAdd5(5, 2) // 15
|
||||
```
|
||||
|
||||
@ -10,5 +10,5 @@ const powerset = arr =>
|
||||
```
|
||||
|
||||
```js
|
||||
powerset([1,2]) -> [[], [1], [2], [2,1]]
|
||||
powerset([1,2]) // [[], [1], [2], [2,1]]
|
||||
```
|
||||
|
||||
@ -15,5 +15,5 @@ const primes = num => {
|
||||
```
|
||||
|
||||
```js
|
||||
primes(10) -> [2,3,5,7]
|
||||
primes(10) // [2,3,5,7]
|
||||
```
|
||||
|
||||
@ -18,5 +18,5 @@ const promisify = func =>
|
||||
|
||||
```js
|
||||
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
|
||||
```
|
||||
|
||||
@ -19,9 +19,9 @@ const pull = (arr, ...args) => {
|
||||
```js
|
||||
let myArray1 = ['a', 'b', 'c', 'a', 'b', 'c'];
|
||||
pull(myArray1, 'a', 'c');
|
||||
console.log(myArray1) -> [ 'b', 'b' ]
|
||||
console.log(myArray1) // [ 'b', 'b' ]
|
||||
|
||||
let myArray2 = ['a', 'b', 'c', 'a', 'b', 'c'];
|
||||
pull(myArray2, ['a', 'c']);
|
||||
console.log(myArray2) -> [ 'b', 'b' ]
|
||||
console.log(myArray2) // [ 'b', 'b' ]
|
||||
```
|
||||
|
||||
@ -21,6 +21,6 @@ const pullAtIndex = (arr, pullArr) => {
|
||||
let myArray = ['a', 'b', 'c', 'd'];
|
||||
let pulled = pullAtIndex(myArray, [1, 3]);
|
||||
|
||||
console.log(myArray); -> [ 'a', 'c' ]
|
||||
console.log(pulled); -> [ 'b', 'd' ]
|
||||
console.log(myArray); // [ 'a', 'c' ]
|
||||
console.log(pulled); // [ 'b', 'd' ]
|
||||
```
|
||||
|
||||
@ -20,6 +20,6 @@ const pullAtValue = (arr, pullArr) => {
|
||||
```js
|
||||
let myArray = ['a', 'b', 'c', 'd'];
|
||||
let pulled = pullAtValue(myArray, ['b', 'd']);
|
||||
console.log(myArray); -> [ 'a', 'c' ]
|
||||
console.log(pulled); -> [ 'b', 'd' ]
|
||||
console.log(myArray); // [ 'a', 'c' ]
|
||||
console.log(pulled); // [ 'b', 'd' ]
|
||||
```
|
||||
|
||||
@ -9,7 +9,7 @@ const randomHexColorCode = () => '#'+(Math.random()*0xFFFFFF<<0).toString(16);
|
||||
```
|
||||
|
||||
```js
|
||||
randomHexColorCode() -> "#e34155"
|
||||
randomHexColorCode() -> "#fd73a6"
|
||||
randomHexColorCode() -> "#4144c6"
|
||||
randomHexColorCode() // "#e34155"
|
||||
randomHexColorCode() // "#fd73a6"
|
||||
randomHexColorCode() // "#4144c6"
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const randomIntegerInRange = (min, max) => Math.floor(Math.random() * (max - min
|
||||
```
|
||||
|
||||
```js
|
||||
randomIntegerInRange(0, 5) -> 2
|
||||
randomIntegerInRange(0, 5) // 2
|
||||
```
|
||||
|
||||
@ -9,5 +9,5 @@ const randomNumberInRange = (min, max) => Math.random() * (max - min) + min;
|
||||
```
|
||||
|
||||
```js
|
||||
randomNumberInRange(2,10) -> 6.0211363285087005
|
||||
randomNumberInRange(2,10) // 6.0211363285087005
|
||||
```
|
||||
|
||||
@ -18,5 +18,5 @@ contents of test.txt :
|
||||
line3
|
||||
___________________________
|
||||
let arr = readFileLines('test.txt')
|
||||
console.log(arr) // -> ['line1', 'line2', 'line3']
|
||||
console.log(arr) // // ['line1', 'line2', 'line3']
|
||||
```
|
||||
|
||||
@ -14,5 +14,5 @@ const remove = (arr, func) =>
|
||||
```
|
||||
|
||||
```js
|
||||
remove([1, 2, 3, 4], n => n % 2 == 0) -> [2, 4]
|
||||
remove([1, 2, 3, 4], n => n % 2 == 0) // [2, 4]
|
||||
```
|
||||
|
||||
@ -11,6 +11,6 @@ const repeatString = (str="",num=2) => {
|
||||
```
|
||||
|
||||
```js
|
||||
repeatString("abc",3) -> 'abcabcabc'
|
||||
repeatString("abc") -> 'abcabc'
|
||||
repeatString("abc",3) // 'abcabcabc'
|
||||
repeatString("abc") // 'abcabc'
|
||||
```
|
||||
|
||||
@ -10,5 +10,5 @@ const reverseString = str => str.split('').reverse().join('');
|
||||
```
|
||||
|
||||
```js
|
||||
reverseString('foobar') -> 'raboof'
|
||||
reverseString('foobar') // 'raboof'
|
||||
```
|
||||
|
||||
@ -10,5 +10,5 @@ const round = (n, decimals=0) => Number(`${Math.round(`${n}e${decimals}`)}e-${de
|
||||
```
|
||||
|
||||
```js
|
||||
round(1.005, 2) -> 1.01
|
||||
round(1.005, 2) // 1.01
|
||||
```
|
||||
|
||||
@ -10,5 +10,5 @@ const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.r
|
||||
|
||||
```js
|
||||
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
|
||||
```
|
||||
|
||||
@ -10,5 +10,5 @@ const sample = arr => arr[Math.floor(Math.random() * arr.length)];
|
||||
```
|
||||
|
||||
```js
|
||||
sample([3, 7, 9, 11]) -> 9
|
||||
sample([3, 7, 9, 11]) // 9
|
||||
```
|
||||
|
||||
@ -11,5 +11,5 @@ const select = (from, selector) =>
|
||||
|
||||
```js
|
||||
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
Reference in New Issue
Block a user