From 05e3f6dc07d94ba359bded5868cedd44772eb0d1 Mon Sep 17 00:00:00 2001 From: Isabelle Viktoria Maciohsek Date: Tue, 3 Nov 2020 22:11:18 +0200 Subject: [PATCH] Format snippets --- snippets/CSVToJSON.md | 6 ++++-- snippets/RGBToHex.md | 3 ++- snippets/bindAll.md | 3 ++- snippets/colorize.md | 2 +- snippets/countBy.md | 3 ++- snippets/elementContains.md | 5 ++++- snippets/isSameDate.md | 3 ++- snippets/luhnCheck.md | 5 ++++- snippets/matches.md | 4 ++-- snippets/queryStringToObject.md | 3 ++- snippets/reduceWhich.md | 6 +++++- snippets/renderElement.md | 21 +++++++++------------ snippets/sumBy.md | 4 +++- 13 files changed, 42 insertions(+), 26 deletions(-) diff --git a/snippets/CSVToJSON.md b/snippets/CSVToJSON.md index 40c76fbfb..e14a57226 100644 --- a/snippets/CSVToJSON.md +++ b/snippets/CSVToJSON.md @@ -28,6 +28,8 @@ const CSVToJSON = (data, delimiter = ',') => { ``` ```js -CSVToJSON('col1,col2\na,b\nc,d'); // [{'col1': 'a', 'col2': 'b'}, {'col1': 'c', 'col2': 'd'}]; -CSVToJSON('col1;col2\na;b\nc;d', ';'); // [{'col1': 'a', 'col2': 'b'}, {'col1': 'c', 'col2': 'd'}]; +CSVToJSON('col1,col2\na,b\nc,d'); +// [{'col1': 'a', 'col2': 'b'}, {'col1': 'c', 'col2': 'd'}]; +CSVToJSON('col1;col2\na;b\nc;d', ';'); +// [{'col1': 'a', 'col2': 'b'}, {'col1': 'c', 'col2': 'd'}]; ``` diff --git a/snippets/RGBToHex.md b/snippets/RGBToHex.md index 91a21823f..988772038 100644 --- a/snippets/RGBToHex.md +++ b/snippets/RGBToHex.md @@ -9,7 +9,8 @@ Converts the values of RGB components to a hexadecimal color code. - Use `String.prototype.padStart(6, '0')` to get a 6-digit hexadecimal value. ```js -const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0'); +const RGBToHex = (r, g, b) => + ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0'); ``` ```js diff --git a/snippets/bindAll.md b/snippets/bindAll.md index e6ccb29a2..a88371b9d 100644 --- a/snippets/bindAll.md +++ b/snippets/bindAll.md @@ -28,5 +28,6 @@ var view = { } }; bindAll(view, 'click'); -document.body.addEventListener('click', view.click); // Log 'clicked docs' when clicked. +document.body.addEventListener('click', view.click); +// Log 'clicked docs' when clicked. ``` diff --git a/snippets/colorize.md b/snippets/colorize.md index 7883e4900..a203fd157 100644 --- a/snippets/colorize.md +++ b/snippets/colorize.md @@ -32,6 +32,6 @@ const colorize = (...args) => ({ ```js console.log(colorize('foo').red); // 'foo' (red letters) console.log(colorize('foo', 'bar').bgBlue); // 'foo bar' (blue background) -console.log(colorize(colorize('foo').yellow, colorize('foo').green).bgWhite); +console.log(colorize(colorize('foo').yellow, colorize('foo').green).bgWhite); // 'foo bar' (first word in yellow letters, second word in green letters, white background for both) ``` diff --git a/snippets/countBy.md b/snippets/countBy.md index 910f8f846..3d3edfd2c 100644 --- a/snippets/countBy.md +++ b/snippets/countBy.md @@ -19,5 +19,6 @@ const countBy = (arr, fn) => ```js countBy([6.1, 4.2, 6.3], Math.floor); // {4: 1, 6: 2} countBy(['one', 'two', 'three'], 'length'); // {3: 2, 5: 1} -countBy([{ count: 5 }, { count: 10 }, { count: 5 }], x => x.count) // {5: 2, 10: 1} +countBy([{ count: 5 }, { count: 10 }, { count: 5 }], x => x.count) +// {5: 2, 10: 1} ``` diff --git a/snippets/elementContains.md b/snippets/elementContains.md index 90707ba29..126671b48 100644 --- a/snippets/elementContains.md +++ b/snippets/elementContains.md @@ -14,7 +14,10 @@ const elementContains = (parent, child) => ``` ```js -elementContains(document.querySelector('head'), document.querySelector('title')); +elementContains( + document.querySelector('head'), + document.querySelector('title') +); // true elementContains(document.querySelector('body'), document.querySelector('body')); // false diff --git a/snippets/isSameDate.md b/snippets/isSameDate.md index 4d77e63f3..45db65d47 100644 --- a/snippets/isSameDate.md +++ b/snippets/isSameDate.md @@ -8,7 +8,8 @@ Checks if a date is the same as another date. - Use `Date.prototype.toISOString()` and strict equality checking (`===`) to check if the first date is the same as the second one. ```js -const isSameDate = (dateA, dateB) => dateA.toISOString() === dateB.toISOString(); +const isSameDate = (dateA, dateB) => + dateA.toISOString() === dateB.toISOString(); ``` ```js diff --git a/snippets/luhnCheck.md b/snippets/luhnCheck.md index a86e7f46c..42bf9f318 100644 --- a/snippets/luhnCheck.md +++ b/snippets/luhnCheck.md @@ -17,7 +17,10 @@ const luhnCheck = num => { .reverse() .map(x => parseInt(x)); let lastDigit = arr.splice(0, 1)[0]; - let sum = arr.reduce((acc, val, i) => (i % 2 !== 0 ? acc + val : acc + ((val * 2) % 9) || 9), 0); + let sum = arr.reduce( + (acc, val, i) => (i % 2 !== 0 ? acc + val : acc + ((val * 2) % 9) || 9), + 0 + ); sum += lastDigit; return sum % 10 === 0; }; diff --git a/snippets/matches.md b/snippets/matches.md index f0cbeac36..071968fe0 100644 --- a/snippets/matches.md +++ b/snippets/matches.md @@ -16,8 +16,8 @@ const matches = (obj, source) => ``` ```js -matches({ age: 25, hair: 'long', beard: true }, { hair: 'long', beard: true }); +matches({ age: 25, hair: 'long', beard: true }, { hair: 'long', beard: true }); // true -matches({ hair: 'long', beard: true }, { age: 25, hair: 'long', beard: true }); +matches({ hair: 'long', beard: true }, { age: 25, hair: 'long', beard: true }); // false ``` diff --git a/snippets/queryStringToObject.md b/snippets/queryStringToObject.md index d4b52ce72..64a284918 100644 --- a/snippets/queryStringToObject.md +++ b/snippets/queryStringToObject.md @@ -18,5 +18,6 @@ const queryStringToObject = url => ``` ```js -queryStringToObject('https://google.com?page=1&count=10'); // {page: '1', count: '10'} +queryStringToObject('https://google.com?page=1&count=10'); +// {page: '1', count: '10'} ``` diff --git a/snippets/reduceWhich.md b/snippets/reduceWhich.md index 6f0552ec3..4ec4f7632 100644 --- a/snippets/reduceWhich.md +++ b/snippets/reduceWhich.md @@ -17,7 +17,11 @@ const reduceWhich = (arr, comparator = (a, b) => a - b) => reduceWhich([1, 3, 2]); // 1 reduceWhich([1, 3, 2], (a, b) => b - a); // 3 reduceWhich( - [{ name: 'Tom', age: 12 }, { name: 'Jack', age: 18 }, { name: 'Lucy', age: 9 }], + [ + { name: 'Tom', age: 12 }, + { name: 'Jack', age: 18 }, + { name: 'Lucy', age: 9 } + ], (a, b) => a.age - b.age ); // {name: 'Lucy', age: 9} ``` diff --git a/snippets/renderElement.md b/snippets/renderElement.md index 179f2ea46..a32bdc4ed 100644 --- a/snippets/renderElement.md +++ b/snippets/renderElement.md @@ -22,16 +22,18 @@ const renderElement = ({ type, props = {} }, container) => { const isAttribute = p => !isListener(p) && p !== 'children'; Object.keys(props).forEach(p => { - if(isAttribute(p)) element[p] = props[p]; - if(!isTextElement && isListener(p)) + if (isAttribute(p)) element[p] = props[p]; + if (!isTextElement && isListener(p)) element.addEventListener(p.toLowerCase().slice(2), props[p]); }); - if(!isTextElement && props.children && props.children.length) - props.children.forEach(childElement => renderElement(childElement, element)); + if (!isTextElement && props.children && props.children.length) + props.children.forEach(childElement => + renderElement(childElement, element) + ); container.appendChild(element); -} +}; ``` ```js @@ -41,14 +43,9 @@ const myElement = { type: 'button', className: 'btn', onClick: () => alert('Clicked'), - children: [ - { props: { nodeValue: 'Click me' } } - ] + children: [{ props: { nodeValue: 'Click me' } }] } }; -renderElement( - myElement, - document.body -); +renderElement(myElement, document.body); ``` diff --git a/snippets/sumBy.md b/snippets/sumBy.md index 5383a78d4..d30447dbe 100644 --- a/snippets/sumBy.md +++ b/snippets/sumBy.md @@ -10,7 +10,9 @@ Calculates the sum of an array, after mapping each element to a value using the ```js const sumBy = (arr, fn) => - arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val) => acc + val, 0); + arr + .map(typeof fn === 'function' ? fn : val => val[fn]) + .reduce((acc, val) => acc + val, 0); ``` ```js