diff --git a/snippets/cleanObj.md b/snippets/cleanObj.md index f2a915719..b8377fd0d 100644 --- a/snippets/cleanObj.md +++ b/snippets/cleanObj.md @@ -15,9 +15,10 @@ const cleanObj = (obj, keysToKeep = [], childIndicator) => { } }) } -/* - const testObj = {a: 1, b: 2, children: {a: 1, b: 2}} - cleanObj(testObj, ["a"],"children") - console.log(testObj)// { a: 1, children : { a: 1}} -*/ +``` + +```js +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/coalesce.md b/snippets/coalesce.md index 22271dc68..9762a363f 100644 --- a/snippets/coalesce.md +++ b/snippets/coalesce.md @@ -6,5 +6,8 @@ Use `Array.find()` to return the first non `null`/`undefined` argument. ```js const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_)) -// coalesce(null,undefined,"",NaN, "Waldo") -> "" +``` + +```js +coalesce(null,undefined,"",NaN, "Waldo") -> "" ``` diff --git a/snippets/coalesceFactory.md b/snippets/coalesceFactory.md index 4b9a78924..39bb98714 100644 --- a/snippets/coalesceFactory.md +++ b/snippets/coalesceFactory.md @@ -6,6 +6,9 @@ Use `Array.find()` to return the first argument that returns `true` from the pro ```js const coalesceFactory = valid => (...args) => args.find(valid); -// const customCoalesce = coalesceFactory(_ => ![null, undefined, "", NaN].includes(_)) -// customCoalesce(undefined, null, NaN, "", "Waldo") //-> "Waldo" +``` + +```js +const customCoalesce = coalesceFactory(_ => ![null, undefined, "", NaN].includes(_)) +customCoalesce(undefined, null, NaN, "", "Waldo") // "Waldo" ``` diff --git a/snippets/collatz.md b/snippets/collatz.md index 8b8903886..fc05b2a5d 100644 --- a/snippets/collatz.md +++ b/snippets/collatz.md @@ -6,6 +6,9 @@ If `n` is even, return `n/2`. Otherwise, return `3n+1`. ```js const collatz = n => (n % 2 == 0) ? (n / 2) : (3 * n + 1); -// collatz(8) --> 4 -// collatz(5) --> 16 +``` + +```js +collatz(8) -> 4 +collatz(5) -> 16 ``` diff --git a/snippets/collectInto.md b/snippets/collectInto.md index c9a823d3d..141a13fa2 100644 --- a/snippets/collectInto.md +++ b/snippets/collectInto.md @@ -6,11 +6,12 @@ Given a function, return a closure that collects all inputs into an array-accept ```js const collectInto = fn => ( ...args ) => fn( args ); -/* +``` + +```js const Pall = collectInto( Promise.all.bind(Promise) ) let p1 = Promise.resolve(1) let p2 = Promise.resolve(2) let p3 = new Promise((resolve) => setTimeout(resolve,2000,3)) Pall(p1, p2, p3).then(console.log) -*/ -``` +``` diff --git a/snippets/compact.md b/snippets/compact.md index d09160afe..2a9528772 100644 --- a/snippets/compact.md +++ b/snippets/compact.md @@ -6,5 +6,8 @@ Use `Array.filter()` to filter out falsey values (`false`, `null`, `0`, `""`, `u ```js const compact = arr => arr.filter(Boolean); -// compact([0, 1, false, 2, '', 3, 'a', 'e'*23, NaN, 's', 34]) -> [ 1, 2, 3, 'a', 's', 34 ] +``` + +```js +compact([0, 1, false, 2, '', 3, 'a', 'e'*23, NaN, 's', 34]) -> [ 1, 2, 3, 'a', 's', 34 ] ``` diff --git a/snippets/compose.md b/snippets/compose.md index f6b1ce2ea..dfd40f814 100644 --- a/snippets/compose.md +++ b/snippets/compose.md @@ -7,10 +7,11 @@ The last (rightmost) function can accept one or more arguments; the remaining fu ```js const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args))); -/* +``` + +```js const add5 = x => x + 5 const multiply = (x, y) => x * y const multiplyAndAdd5 = compose(add5, multiply) multiplyAndAdd5(5, 2) -> 15 -*/ ``` diff --git a/snippets/countOccurrences.md b/snippets/countOccurrences.md index f55de0a62..2c1463b02 100644 --- a/snippets/countOccurrences.md +++ b/snippets/countOccurrences.md @@ -6,5 +6,8 @@ Use `Array.reduce()` to increment a counter each time you encounter the specific ```js const countOccurrences = (arr, value) => arr.reduce((a, v) => v === value ? a + 1 : a + 0, 0); -// countOccurrences([1,1,2,1,2,3], 1) -> 3 +``` + +```js +countOccurrences([1,1,2,1,2,3], 1) -> 3 ``` diff --git a/snippets/countVowels.md b/snippets/countVowels.md index c91f09442..47c683eb8 100644 --- a/snippets/countVowels.md +++ b/snippets/countVowels.md @@ -6,6 +6,9 @@ Use a regular expression to count the number of vowels `(A, E, I, O, U)` in a `s ```js const countVowels = str => (str.match(/[aeiou]/ig) || []).length; -// countVowels('foobar') -> 3 -// countVowels('gym') -> 0 +``` + +```js +countVowels('foobar') -> 3 +countVowels('gym') -> 0 ``` diff --git a/snippets/currentURL.md b/snippets/currentURL.md index a6482a689..7e8965d92 100644 --- a/snippets/currentURL.md +++ b/snippets/currentURL.md @@ -6,5 +6,8 @@ Use `window.location.href` to get current URL. ```js const currentURL = () => window.location.href; -// currentUrl() -> 'https://google.com' +``` + +```js +currentUrl() -> 'https://google.com' ``` diff --git a/snippets/curry.md b/snippets/curry.md index c88e3418a..f1806d395 100644 --- a/snippets/curry.md +++ b/snippets/curry.md @@ -12,6 +12,9 @@ const curry = (fn, arity = fn.length, ...args) => arity <= args.length ? fn(...args) : curry.bind(null, fn, arity, ...args); -// curry(Math.pow)(2)(10) -> 1024 -// curry(Math.min, 3)(10)(50)(2) -> 2 +``` + +```js +curry(Math.pow)(2)(10) -> 1024 +curry(Math.min, 3)(10)(50)(2) -> 2 ``` diff --git a/snippets/deepFlatten.md b/snippets/deepFlatten.md index c6f29fb9b..cea888992 100644 --- a/snippets/deepFlatten.md +++ b/snippets/deepFlatten.md @@ -8,5 +8,8 @@ Recursively flatten each element that is an array. ```js const deepFlatten = arr => [].concat(...arr.map(v => Array.isArray(v) ? deepFlatten(v) : v)); -// deepFlatten([1,[2],[[3],4],5]) -> [1,2,3,4,5] +``` + +```js +deepFlatten([1,[2],[[3],4],5]) -> [1,2,3,4,5] ``` diff --git a/snippets/detectDeviceType.md b/snippets/detectDeviceType.md index b2822a458..64888d44e 100644 --- a/snippets/detectDeviceType.md +++ b/snippets/detectDeviceType.md @@ -6,6 +6,9 @@ Use a regular expression to test the `navigator.userAgent` property to figure ou ```js const detectDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? "Mobile" : "Desktop"; -// detectDeviceType() -> "Mobile" -// detectDeviceType() -> "Desktop" +``` + +```js +detectDeviceType() -> "Mobile" +detectDeviceType() -> "Desktop" ``` diff --git a/snippets/difference.md b/snippets/difference.md index e78a73340..dce891e60 100644 --- a/snippets/difference.md +++ b/snippets/difference.md @@ -6,5 +6,8 @@ Create a `Set` from `b`, then use `Array.filter()` on `a` to only keep values no ```js const difference = (a, b) => { const s = new Set(b); return a.filter(x => !s.has(x)); }; -// difference([1,2,3], [1,2,4]) -> [3] +``` + +```js +difference([1,2,3], [1,2,4]) -> [3] ``` diff --git a/snippets/differenceWith.md b/snippets/differenceWith.md index ba4aac0ec..c199a62bd 100644 --- a/snippets/differenceWith.md +++ b/snippets/differenceWith.md @@ -6,5 +6,8 @@ Use `Array.filter()` and `Array.find()` to find the appropriate values. ```js const differenceWith = (arr, val, comp) => arr.filter(a => !val.find(b => comp(a, b))) -// differenceWith([1, 1.2, 1.5, 3], [1.9, 3], (a,b) => Math.round(a) == Math.round(b)) -> [1, 1.2] +``` + +```js +differenceWith([1, 1.2, 1.5, 3], [1.9, 3], (a,b) => Math.round(a) == Math.round(b)) -> [1, 1.2] ```