diff --git a/snippets/JSONToDate.md b/snippets/JSONToDate.md index ce3ceebdb..c5fa32175 100644 --- a/snippets/JSONToDate.md +++ b/snippets/JSONToDate.md @@ -9,5 +9,5 @@ const JSONToDate = arr => { const dt = new Date(parseInt(arr.toString().substr(6))); return `${ dt.getDate() }/${ dt.getMonth() + 1 }/${ dt.getFullYear() }` }; -// jsonToDate(/Date(1489525200000)/) -> "14/3/2017" +// JSONToDate(/Date(1489525200000)/) -> "14/3/2017" ``` diff --git a/snippets/JSONToFile.md b/snippets/JSONToFile.md index f7f0990a1..3677fc5e3 100644 --- a/snippets/JSONToFile.md +++ b/snippets/JSONToFile.md @@ -7,5 +7,5 @@ Use `fs.writeFile()`, template literals and `JSON.stringify()` to write a `json` ```js const fs = require('fs'); const JSONToFile = (obj, filename) => fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2)) -// jsonToFile({test: "is passed"}, 'testJsonFile') -> writes the object to 'testJsonFile.json' +// JSONToFile({test: "is passed"}, 'testJsonFile') -> writes the object to 'testJsonFile.json' ``` diff --git a/snippets/RGBToHex.md b/snippets/RGBToHex.md index 23dce9ec4..64e880798 100644 --- a/snippets/RGBToHex.md +++ b/snippets/RGBToHex.md @@ -6,5 +6,5 @@ Convert given RGB parameters to hexadecimal string using bitwise left-shift oper ```js const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0'); -// rgbToHex(255, 165, 1) -> 'ffa501' +// RGBToHex(255, 165, 1) -> 'ffa501' ``` diff --git a/snippets/UUIDGenerator.md b/snippets/UUIDGenerator.md index 9fe3343f2..316659ea2 100644 --- a/snippets/UUIDGenerator.md +++ b/snippets/UUIDGenerator.md @@ -9,5 +9,5 @@ const UUIDGenerator = () => ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) ); -// uuid() -> '7982fcfe-5721-4632-bede-6000885be57d' +// UUIDGenerator() -> '7982fcfe-5721-4632-bede-6000885be57d' ``` diff --git a/snippets/arrayAverage.md b/snippets/arrayAverage.md index 8fe610f2d..74c8cef97 100644 --- a/snippets/arrayAverage.md +++ b/snippets/arrayAverage.md @@ -6,5 +6,5 @@ Use `Array.reduce()` to add each value to an accumulator, initialized with a val ```js const arrayAverage = arr => arr.reduce((acc, val) => acc + val, 0) / arr.length; -// average([1,2,3]) -> 2 +// arrayAverage([1,2,3]) -> 2 ``` diff --git a/snippets/arraySum.md b/snippets/arraySum.md index 9c07695db..265c7fc60 100644 --- a/snippets/arraySum.md +++ b/snippets/arraySum.md @@ -6,5 +6,5 @@ Use `Array.reduce()` to add each value to an accumulator, initialized with a val ```js const arraySum = arr => arr.reduce((acc, val) => acc + val, 0); -// sum([1,2,3,4]) -> 10 +// arraySum([1,2,3,4]) -> 10 ``` diff --git a/snippets/cleanObj.md b/snippets/cleanObj.md index 34e443a41..8ba4058ed 100644 --- a/snippets/cleanObj.md +++ b/snippets/cleanObj.md @@ -16,7 +16,7 @@ const cleanObj = (obj, keysToKeep = [], childIndicator) => { }) } /* - testObj = {a: 1, b: 2, children: {a: 1, b: 2}} + const testObj = {a: 1, b: 2, children: {a: 1, b: 2}} cleanObj(testObj, ["a"],"children") console.log(testObj)// { a: 1, children : { a: 1}} */ diff --git a/snippets/distinctValuesOfArray.md b/snippets/distinctValuesOfArray.md index 5b5b8e5e0..24c0c60c0 100644 --- a/snippets/distinctValuesOfArray.md +++ b/snippets/distinctValuesOfArray.md @@ -6,5 +6,5 @@ Use ES6 `Set` and the `...rest` operator to discard all duplicated values. ```js const distinctValuesOfArray = arr => [...new Set(arr)]; -// unique([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] ``` diff --git a/snippets/everyNth.md b/snippets/everyNth.md index 616052b80..0c79e3a1f 100644 --- a/snippets/everyNth.md +++ b/snippets/everyNth.md @@ -6,5 +6,5 @@ Use `Array.filter()` to create a new array that contains every nth element of a ```js const everyNth = (arr, nth) => arr.filter((e, i) => i % nth === 0); -// everynth([1,2,3,4,5,6], 2) -> [ 1, 3, 5 ] +// everyNth([1,2,3,4,5,6], 2) -> [ 1, 3, 5 ] ``` diff --git a/snippets/extendHex.md b/snippets/extendHex.md index 994d592b3..bda2cdd5e 100644 --- a/snippets/extendHex.md +++ b/snippets/extendHex.md @@ -7,6 +7,6 @@ Use `Array.map()`, `split()` and `Array.join()` to join the mapped array for con ```js const extendHex = shortHex => '#' + shortHex.slice(shortHex.startsWith('#') ? 1 : 0).split('').map(x => x+x).join('') -// convertHex('#03f') -> '#0033ff' -// convertHex('05a') -> '#0055aa' +// extendHex('#03f') -> '#0033ff' +// extendHex('05a') -> '#0055aa' ``` diff --git a/snippets/getScrollPosition.md b/snippets/getScrollPosition.md index dee0da298..b51ec3241 100644 --- a/snippets/getScrollPosition.md +++ b/snippets/getScrollPosition.md @@ -9,5 +9,5 @@ You can omit `el` to use a default value of `window`. const getScrollPosition = (el = window) => ({x: (el.pageXOffset !== undefined) ? el.pageXOffset : el.scrollLeft, y: (el.pageYOffset !== undefined) ? el.pageYOffset : el.scrollTop}); -// getScrollPos() -> {x: 0, y: 200} +// getScrollPosition() -> {x: 0, y: 200} ``` diff --git a/snippets/getURLParameters.md b/snippets/getURLParameters.md index c7b432d8a..77dddd532 100644 --- a/snippets/getURLParameters.md +++ b/snippets/getURLParameters.md @@ -10,5 +10,5 @@ const getURLParameters = url => url.match(/([^?=&]+)(=([^&]*))/g).reduce( (a, v) => (a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1), a), {} ); -// 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'} ``` diff --git a/snippets/initializeArrayWithRange.md b/snippets/initializeArrayWithRange.md index 0210314f3..d90de1136 100644 --- a/snippets/initializeArrayWithRange.md +++ b/snippets/initializeArrayWithRange.md @@ -8,5 +8,5 @@ You can omit `start` to use a default value of `0`. ```js const initializeArrayWithRange = (end, start = 0) => Array.from({ length: end - start }).map((v, i) => i + start); -// initializeArrayRange(5) -> [0,1,2,3,4] +// initializeArrayWithRange(5) -> [0,1,2,3,4] ``` diff --git a/snippets/initializeArrayWithValues.md b/snippets/initializeArrayWithValues.md index 6c48d74a7..47459fcdd 100644 --- a/snippets/initializeArrayWithValues.md +++ b/snippets/initializeArrayWithValues.md @@ -7,5 +7,5 @@ You can omit `value` to use a default value of `0`. ```js const initializeArrayWithValues = (n, value = 0) => Array(n).fill(value); -// initializeArray(5, 2) -> [2,2,2,2,2] +// initializeArrayWithValues(5, 2) -> [2,2,2,2,2] ``` diff --git a/snippets/pipe.md b/snippets/pipe.md index b01d5137e..4c6495cda 100644 --- a/snippets/pipe.md +++ b/snippets/pipe.md @@ -10,7 +10,7 @@ const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args) /* const add5 = x => x + 5 const multiply = (x, y) => x * y -const multiplyAndAdd5 = pipe(multiply, add5) +const multiplyAndAdd5 = pipeFunctions(multiply, add5) multiplyAndAdd5(5, 2) -> 15 */ ``` diff --git a/snippets/randomNumberInRange.md b/snippets/randomNumberInRange.md index e0e329cce..a92dfff54 100644 --- a/snippets/randomNumberInRange.md +++ b/snippets/randomNumberInRange.md @@ -6,5 +6,5 @@ Use `Math.random()` to generate a random value, map it to the desired range usin ```js const randomNumberInRange = (min, max) => Math.random() * (max - min) + min; -// randomInRange(2,10) -> 6.0211363285087005 +// randomNumberInRange(2,10) -> 6.0211363285087005 ``` diff --git a/snippets/readFileLines.md b/snippets/readFileLines.md index f46735aed..288c2ebf8 100644 --- a/snippets/readFileLines.md +++ b/snippets/readFileLines.md @@ -15,7 +15,7 @@ const readFileLines = filename => fs.readFileSync(filename).toString('UTF8').spl line2 line3 ___________________________ - let arr = readFileToArray('test.txt') + let arr = readFileLines('test.txt') console.log(arr) // -> ['line1', 'line2', 'line3'] */ ``` diff --git a/snippets/runPromisesInSeries.md b/snippets/runPromisesInSeries.md index affbae9fe..c1cedb147 100644 --- a/snippets/runPromisesInSeries.md +++ b/snippets/runPromisesInSeries.md @@ -7,5 +7,5 @@ Use `Array.reduce()` to create a promise chain, where each promise returns the n ```js const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.resolve()); // const delay = (d) => new Promise(r => setTimeout(r, d)) -// series([() => 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 ``` diff --git a/snippets/speechSynthesis.md b/snippets/speechSynthesis.md index 954d41d35..cb8d150f4 100644 --- a/snippets/speechSynthesis.md +++ b/snippets/speechSynthesis.md @@ -13,5 +13,5 @@ const speechSynthesis = message => { msg.voice = window.speechSynthesis.getVoices()[0]; window.speechSynthesis.speak(msg); }; -// speak('Hello, World') -> plays the message +// speechSynthesis('Hello, World') -> plays the message ``` diff --git a/snippets/truncateString.md b/snippets/truncateString.md index ea5c00237..48924b0ae 100644 --- a/snippets/truncateString.md +++ b/snippets/truncateString.md @@ -8,5 +8,5 @@ Return the string truncated to the desired length, with `...` appended to the en ```js const truncateString = (str, num) => str.length > num ? str.slice(0, num > 3 ? num - 3 : num) + '...' : str; -// truncate('boomerang', 7) -> 'boom...' +// truncateString('boomerang', 7) -> 'boom...' ```