From e7e687f60c99d4f862c5641d2b97e833460a5de5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Feje=C5=A1?= Date: Mon, 25 Dec 2017 14:49:52 +0100 Subject: [PATCH] update snippets 0-All --- snippets/UUIDGenerator.md | 5 ++++- snippets/round.md | 7 +++++-- snippets/runPromisesInSeries.md | 7 +++++-- snippets/sample.md | 5 ++++- snippets/scrollToTop.md | 5 ++++- snippets/select.md | 8 +++++--- snippets/shallowClone.md | 5 +++-- snippets/shuffle.md | 9 ++++++--- snippets/similarity.md | 5 ++++- snippets/sleep.md | 5 +++-- snippets/sortCharactersInString.md | 5 ++++- snippets/speechSynthesis.md | 5 ++++- snippets/spreadOver.md | 11 ++++++----- snippets/standardDeviation.md | 7 +++++-- snippets/symmetricDifference.md | 7 +++++-- snippets/tail.md | 7 +++++-- snippets/take.md | 7 +++++-- snippets/takeRight.md | 7 +++++-- snippets/timeTaken.md | 7 +++++-- snippets/toCamelCase.md | 15 +++++++++------ snippets/toDecimalMark.md | 7 +++++-- snippets/toEnglishDate.md | 5 ++++- snippets/toKebabCase.md | 13 ++++++++----- snippets/toOrdinalSuffix.md | 5 ++++- snippets/toSnakeCase.md | 15 +++++++++------ snippets/truncateString.md | 5 ++++- snippets/truthCheckCollection.md | 7 +++++-- snippets/union.md | 5 ++++- snippets/validateNumber.md | 5 ++++- snippets/without.md | 5 ++++- snippets/words.md | 7 +++++-- snippets/zip.md | 13 ++++++++----- snippets/zipObject.md | 9 ++++++--- 33 files changed, 166 insertions(+), 74 deletions(-) diff --git a/snippets/UUIDGenerator.md b/snippets/UUIDGenerator.md index 316659ea2..87300e5ed 100644 --- a/snippets/UUIDGenerator.md +++ b/snippets/UUIDGenerator.md @@ -9,5 +9,8 @@ const UUIDGenerator = () => ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) ); -// UUIDGenerator() -> '7982fcfe-5721-4632-bede-6000885be57d' +``` + +```js +UUIDGenerator() -> '7982fcfe-5721-4632-bede-6000885be57d' ``` diff --git a/snippets/round.md b/snippets/round.md index 81e90dfe0..8ece6dcd1 100644 --- a/snippets/round.md +++ b/snippets/round.md @@ -6,6 +6,9 @@ Use `Math.round()` and template literals to round the number to the specified nu Omit the second argument, `decimals` to round to an integer. ```js -const round = (n, decimals = 0) => Number(`${Math.round(`${n}e${decimals}`)}e-${decimals}`); -// round(1.005, 2) -> 1.01 +const round = (n, decimals=0) => Number(`${Math.round(`${n}e${decimals}`)}e-${decimals}`); +``` + +```js +round(1.005, 2) // 1.01 ``` diff --git a/snippets/runPromisesInSeries.md b/snippets/runPromisesInSeries.md index c1cedb147..9719ed6aa 100644 --- a/snippets/runPromisesInSeries.md +++ b/snippets/runPromisesInSeries.md @@ -6,6 +6,9 @@ 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)) -// runPromisesInSeries([() => delay(1000), () => delay(2000)]) -> executes each promise sequentially, taking a total of 3 seconds to complete +``` + +```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 ``` diff --git a/snippets/sample.md b/snippets/sample.md index caf1941e3..078542224 100644 --- a/snippets/sample.md +++ b/snippets/sample.md @@ -7,5 +7,8 @@ This method also works with strings. ```js const sample = arr => arr[Math.floor(Math.random() * arr.length)]; -// sample([3, 7, 9, 11]) -> 9 +``` + +```js +sample([3, 7, 9, 11]) -> 9 ``` diff --git a/snippets/scrollToTop.md b/snippets/scrollToTop.md index 62cad2588..90c0342a8 100644 --- a/snippets/scrollToTop.md +++ b/snippets/scrollToTop.md @@ -13,5 +13,8 @@ const scrollToTop = () => { window.scrollTo(0, c - c / 8); } }; -// scrollToTop() +``` + +```js +scrollToTop() ``` diff --git a/snippets/select.md b/snippets/select.md index ee243bb8e..c3db1e047 100644 --- a/snippets/select.md +++ b/snippets/select.md @@ -7,7 +7,9 @@ If the property does not exists returns `undefined`. ```js const select = (from, selector) => selector.split('.').reduce((prev, cur) => prev && prev[cur], from); - -// const obj = {selector: {to: {val: 'val to select'}}}; -// select(obj, 'selector.to.val'); -> 'val to select' +``` + +```js +const obj = {selector: {to: {val: 'val to select'}}}; +select(obj, 'selector.to.val'); -> 'val to select' ``` diff --git a/snippets/shallowClone.md b/snippets/shallowClone.md index 0a6c25d82..cdef28d9b 100644 --- a/snippets/shallowClone.md +++ b/snippets/shallowClone.md @@ -6,9 +6,10 @@ Use `Object.assign()` and an empty object (`{}`) to create a shallow clone of th ```js const shallowClone = obj => Object.assign({}, obj); -/* +``` + +```js const a = { x: true, y: 1 }; const b = shallowClone(a); a === b -> false -*/ ``` diff --git a/snippets/shuffle.md b/snippets/shuffle.md index fa576b016..4e7f88879 100644 --- a/snippets/shuffle.md +++ b/snippets/shuffle.md @@ -13,7 +13,10 @@ const shuffle = ([...arr]) => { } return arr; }; -// const foo = [1,2,3] -// shuffle(foo) -> [2,3,1] -// console.log(foo) -> [1,2,3] +``` + +```js +const foo = [1,2,3] +shuffle(foo) // [2,3,1] +console.log(foo) // [1,2,3] ``` diff --git a/snippets/similarity.md b/snippets/similarity.md index 1a2cc7ccb..e1f735be2 100644 --- a/snippets/similarity.md +++ b/snippets/similarity.md @@ -6,5 +6,8 @@ Use `filter()` to remove values that are not part of `values`, determined using ```js const similarity = (arr, values) => arr.filter(v => values.includes(v)); -// similarity([1,2,3], [1,2,4]) -> [1,2] +``` + +```js +similarity([1,2,3], [1,2,4]) -> [1,2] ``` diff --git a/snippets/sleep.md b/snippets/sleep.md index 66a45d2ff..69fd73059 100644 --- a/snippets/sleep.md +++ b/snippets/sleep.md @@ -6,11 +6,12 @@ Delay executing part of an `async` function, by putting it to sleep, returning a ```js const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); -/* +``` + +```js async function sleepyWork() { console.log('I\'m going to sleep for 1 second.'); await sleep(1000); console.log('I woke up after 1 second.'); } -*/ ``` diff --git a/snippets/sortCharactersInString.md b/snippets/sortCharactersInString.md index 79c7acc0f..4e7e68cf7 100644 --- a/snippets/sortCharactersInString.md +++ b/snippets/sortCharactersInString.md @@ -7,5 +7,8 @@ Split the string using `split('')`, `Array.sort()` utilizing `localeCompare()`, ```js const sortCharactersInString = str => str.split('').sort((a, b) => a.localeCompare(b)).join(''); -// sortCharactersInString('cabbage') -> 'aabbceg' +``` + +```js +sortCharactersInString('cabbage') -> 'aabbceg' ``` diff --git a/snippets/speechSynthesis.md b/snippets/speechSynthesis.md index cb8d150f4..2ccb55375 100644 --- a/snippets/speechSynthesis.md +++ b/snippets/speechSynthesis.md @@ -13,5 +13,8 @@ const speechSynthesis = message => { msg.voice = window.speechSynthesis.getVoices()[0]; window.speechSynthesis.speak(msg); }; -// speechSynthesis('Hello, World') -> plays the message +``` + +```js +speechSynthesis('Hello, World') -> // plays the message ``` diff --git a/snippets/spreadOver.md b/snippets/spreadOver.md index aff6281a6..d41b1cb36 100644 --- a/snippets/spreadOver.md +++ b/snippets/spreadOver.md @@ -6,9 +6,10 @@ Use closures and the spread operator (`...`) to map the array of arguments to th ```js const spreadOver = fn => argsArr => fn(...argsArr); -/* +``` + +```js const arrayMax = spreadOver(Math.max) -arrayMax([1,2,3]) // -> 3 -arrayMax([1,2,4]) // -> 4 -*/ -``` +arrayMax([1,2,3]) -> 3 +arrayMax([1,2,4]) -> 4 +``` diff --git a/snippets/standardDeviation.md b/snippets/standardDeviation.md index 51cf4a0dd..43d7139fd 100644 --- a/snippets/standardDeviation.md +++ b/snippets/standardDeviation.md @@ -14,6 +14,9 @@ const standardDeviation = (arr, usePopulation = false) => { .reduce((acc, val) => acc + val, 0) / (arr.length - (usePopulation ? 0 : 1)) ); }; -// standardDeviation([10,2,38,23,38,23,21]) -> 13.284434142114991 (sample) -// standardDeviation([10,2,38,23,38,23,21], true) -> 12.29899614287479 (population) +``` + +```js +standardDeviation([10,2,38,23,38,23,21]) -> 13.284434142114991 (sample) +standardDeviation([10,2,38,23,38,23,21], true) -> 12.29899614287479 (population) ``` diff --git a/snippets/symmetricDifference.md b/snippets/symmetricDifference.md index 596adf28a..6879edb39 100644 --- a/snippets/symmetricDifference.md +++ b/snippets/symmetricDifference.md @@ -8,6 +8,9 @@ Create a `Set` from each array, then use `Array.filter()` on each of them to onl const symmetricDifference = (a, b) => { const sA = new Set(a), sB = new Set(b); return [...a.filter(x => !sB.has(x)), ...b.filter(x => !sA.has(x))]; -}; -// symmetricDifference([1,2,3], [1,2,4]) -> [3,4] +} +``` + +```js +symmetricDifference([1,2,3], [1,2,4]) -> [3,4] ``` diff --git a/snippets/tail.md b/snippets/tail.md index 9d84a17f1..69983d169 100644 --- a/snippets/tail.md +++ b/snippets/tail.md @@ -6,6 +6,9 @@ Return `arr.slice(1)` if the array's `length` is more than `1`, otherwise, retur ```js const tail = arr => arr.length > 1 ? arr.slice(1) : arr; -// tail([1,2,3]) -> [2,3] -// tail([1]) -> [1] +``` + +```js +tail([1,2,3]) -> [2,3] +tail([1]) -> [1] ``` diff --git a/snippets/take.md b/snippets/take.md index f6afa5dab..07d25262d 100644 --- a/snippets/take.md +++ b/snippets/take.md @@ -6,6 +6,9 @@ Use `Array.slice()` to create a slice of the array with `n` elements taken from ```js const take = (arr, n = 1) => arr.slice(0, n); -// take([1, 2, 3], 5) -> [1, 2, 3] -// take([1, 2, 3], 0) -> [] +``` + +```js +take([1, 2, 3], 5) -> [1, 2, 3] +take([1, 2, 3], 0) -> [] ``` diff --git a/snippets/takeRight.md b/snippets/takeRight.md index a8fc0e114..45d272ed0 100644 --- a/snippets/takeRight.md +++ b/snippets/takeRight.md @@ -6,6 +6,9 @@ Use `Array.slice()` to create a slice of the array with `n` elements taken from ```js const takeRight = (arr, n = 1) => arr.slice(arr.length - n, arr.length); -// takeRight([1, 2, 3], 2) -> [ 2, 3 ] -// takeRight([1, 2, 3]) -> [3] +``` + +```js +takeRight([1, 2, 3], 2) -> [ 2, 3 ] +takeRight([1, 2, 3]) -> [3] ``` diff --git a/snippets/timeTaken.md b/snippets/timeTaken.md index 05b16fb46..b75402b9b 100644 --- a/snippets/timeTaken.md +++ b/snippets/timeTaken.md @@ -9,6 +9,9 @@ const timeTaken = callback => { console.time('timeTaken'); const r = callback(); console.timeEnd('timeTaken'); return r; }; -// timeTaken(() => Math.pow(2, 10)) -> 1024 -// (logged): timeTaken: 0.02099609375ms +``` + +```js +timeTaken(() => Math.pow(2, 10)) -> 1024 +(logged): timeTaken: 0.02099609375ms ``` diff --git a/snippets/toCamelCase.md b/snippets/toCamelCase.md index c3c78e8e9..366a988dd 100644 --- a/snippets/toCamelCase.md +++ b/snippets/toCamelCase.md @@ -10,10 +10,13 @@ const toCamelCase = str => { let s = str && str.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g) .map(x => x.slice(0, 1).toUpperCase() + x.slice(1).toLowerCase()) .join(''); - return s.slice(0, 1).toLowerCase() + s.slice(1); -}; -// toCamelCase("some_database_field_name") -> 'someDatabaseFieldName' -// toCamelCase("Some label that needs to be camelized") -> 'someLabelThatNeedsToBeCamelized' -// toCamelCase("some-javascript-property") -> 'someJavascriptProperty' -// toCamelCase("some-mixed_string with spaces_underscores-and-hyphens") -> 'someMixedStringWithSpacesUnderscoresAndHyphens' + return s.slice(0,1).toLowerCase() + s.slice(1) + } +``` + +```js +toCamelCase("some_database_field_name") -> 'someDatabaseFieldName' +toCamelCase("Some label that needs to be camelized") -> 'someLabelThatNeedsToBeCamelized' +toCamelCase("some-javascript-property") -> 'someJavascriptProperty' +toCamelCase("some-mixed_string with spaces_underscores-and-hyphens") -> 'someMixedStringWithSpacesUnderscoresAndHyphens' ``` diff --git a/snippets/toDecimalMark.md b/snippets/toDecimalMark.md index b05429817..b670622cd 100644 --- a/snippets/toDecimalMark.md +++ b/snippets/toDecimalMark.md @@ -3,6 +3,9 @@ Use `toLocaleString()` to convert a float-point arithmetic to the [Decimal mark](https://en.wikipedia.org/wiki/Decimal_mark) form. It makes a comma separated string from a number. ```js -const toDecimalMark = num => num.toLocaleString('en-US'); -// toDecimalMark(12305030388.9087) -> "12,305,030,388.9087" +const toDecimalMark = num => num.toLocaleString("en-US"); +``` + +```js +toDecimalMark(12305030388.9087) // "12,305,030,388.9087" ``` diff --git a/snippets/toEnglishDate.md b/snippets/toEnglishDate.md index ffbcf6cd7..30a4c1f2c 100644 --- a/snippets/toEnglishDate.md +++ b/snippets/toEnglishDate.md @@ -7,5 +7,8 @@ Throws an error if the passed time cannot be converted to a date. ```js const toEnglishDate = (time) => { try { return new Date(time).toISOString().split('T')[0].replace(/-/g, '/'); } catch (e) {} }; -// toEnglishDate('09/21/2010') -> '21/09/2010' +``` + +```js +toEnglishDate('09/21/2010') // '21/09/2010' ``` diff --git a/snippets/toKebabCase.md b/snippets/toKebabCase.md index 20c7e2546..50b7ead16 100644 --- a/snippets/toKebabCase.md +++ b/snippets/toKebabCase.md @@ -10,9 +10,12 @@ const toKebabCase = str => str && str.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g) .map(x => x.toLowerCase()) .join('-'); -// toKebabCase("camelCase") -> 'camel-case' -// toKebabCase("some text") -> 'some-text' -// toKebabCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some-mixed-string-with-spaces-underscores-and-hyphens' -// toKebabCase("AllThe-small Things") -> "all-the-small-things" -// toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML') -> "i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-xml-and-html" +``` + +```js +toKebabCase("camelCase") -> 'camel-case' +toKebabCase("some text") -> 'some-text' +toKebabCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some-mixed-string-with-spaces-underscores-and-hyphens' +toKebabCase("AllThe-small Things") -> "all-the-small-things" +toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML') -> "i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-xml-and-html" ``` diff --git a/snippets/toOrdinalSuffix.md b/snippets/toOrdinalSuffix.md index 482286056..53541c162 100644 --- a/snippets/toOrdinalSuffix.md +++ b/snippets/toOrdinalSuffix.md @@ -13,5 +13,8 @@ const toOrdinalSuffix = num => { tPattern = [11, 12, 13, 14, 15, 16, 17, 18, 19]; return oPattern.includes(digits[0]) && !tPattern.includes(digits[1]) ? int + ordinals[digits[0] - 1] : int + ordinals[3]; }; -// toOrdinalSuffix("123") -> "123rd" +``` + +```js +toOrdinalSuffix("123") -> "123rd" ``` diff --git a/snippets/toSnakeCase.md b/snippets/toSnakeCase.md index b4022f98d..72ed59aa4 100644 --- a/snippets/toSnakeCase.md +++ b/snippets/toSnakeCase.md @@ -11,10 +11,13 @@ const toSnakeCase = str => { .map(x => x.toLowerCase()) .join('_'); }; -// toSnakeCase("camelCase") -> 'camel_case' -// toSnakeCase("some text") -> 'some_text' -// toSnakeCase("some-javascript-property") -> 'some_javascript_property' -// toSnakeCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some_mixed_string_with_spaces_underscores_and_hyphens' -// toSnakeCase("AllThe-small Things") -> "all_the_small_things" -// toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML') -> "i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html" +``` + +```js +toSnakeCase("camelCase") -> 'camel_case' +toSnakeCase("some text") -> 'some_text' +toSnakeCase("some-javascript-property") -> 'some_javascript_property' +toSnakeCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some_mixed_string_with_spaces_underscores_and_hyphens' +toSnakeCase("AllThe-small Things") -> "all_the_smal_things" +toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML') -> "i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html" ``` diff --git a/snippets/truncateString.md b/snippets/truncateString.md index 48924b0ae..56561cc7f 100644 --- a/snippets/truncateString.md +++ b/snippets/truncateString.md @@ -8,5 +8,8 @@ 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; -// truncateString('boomerang', 7) -> 'boom...' +``` + +```js +truncateString('boomerang', 7) -> 'boom...' ``` diff --git a/snippets/truthCheckCollection.md b/snippets/truthCheckCollection.md index 3c592d308..a2c4cb35e 100644 --- a/snippets/truthCheckCollection.md +++ b/snippets/truthCheckCollection.md @@ -3,8 +3,11 @@ Checks if the predicate (second argument) is truthy on all elements of a collection (first argument). Use `Array.every()` to check if each passed object has the specified property and if it returns a truthy value. - + ```js const truthCheckCollection = (collection, pre) => (collection.every(obj => obj[pre])); -// truthCheckCollection([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}], "sex") -> true +``` + +```js +truthCheckCollection([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}], "sex") -> true ``` diff --git a/snippets/union.md b/snippets/union.md index 27427a9aa..d141d2a3e 100644 --- a/snippets/union.md +++ b/snippets/union.md @@ -6,5 +6,8 @@ Create a `Set` with all values of `a` and `b` and convert to an array. ```js const union = (a, b) => Array.from(new Set([...a, ...b])); -// union([1,2,3], [4,3,2]) -> [1,2,3,4] +``` + +```js +union([1,2,3], [4,3,2]) -> [1,2,3,4] ``` diff --git a/snippets/validateNumber.md b/snippets/validateNumber.md index 8874cfce2..075e6b4f9 100644 --- a/snippets/validateNumber.md +++ b/snippets/validateNumber.md @@ -8,5 +8,8 @@ Use `Number()` to check if the coercion holds. ```js const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == n; -// validateNumber('10') -> true +``` + +```js +validateNumber('10') -> true ``` diff --git a/snippets/without.md b/snippets/without.md index 532ec26d9..044f2e8f6 100644 --- a/snippets/without.md +++ b/snippets/without.md @@ -8,5 +8,8 @@ _(For a snippet that mutates the original array see [`pull`](#pull))_ ```js const without = (arr, ...args) => arr.filter(v => !args.includes(v)); -// without([2, 1, 2, 3], 1, 2) -> [3] +``` + +```js +without([2, 1, 2, 3], 1, 2) -> [3] ``` diff --git a/snippets/words.md b/snippets/words.md index df6b258b7..47d70659d 100644 --- a/snippets/words.md +++ b/snippets/words.md @@ -7,6 +7,9 @@ Omit the second argument to use the default regex. ```js const words = (str, pattern = /[^a-zA-Z-]+/) => str.split(pattern).filter(Boolean); -// words("I love javaScript!!") -> ["I", "love", "javaScript"] -// words("python, javaScript & coffee") -> ["python", "javaScript", "coffee"] +``` + +```js +words("I love javaScript!!") -> ["I", "love", "javaScript"] +words("python, javaScript & coffee") -> ["python", "javaScript", "coffee"] ``` diff --git a/snippets/zip.md b/snippets/zip.md index 981143fd5..92613ff34 100644 --- a/snippets/zip.md +++ b/snippets/zip.md @@ -10,9 +10,12 @@ If lengths of the argument-arrays vary, `undefined` is used where no value could const zip = (...arrays) => { const maxLength = Math.max(...arrays.map(x => x.length)); return Array.from({length: maxLength}).map((_, i) => { - return Array.from({length: arrays.length}, (_, k) => arrays[k][i]); - }); -}; -// zip(['a', 'b'], [1, 2], [true, false]); -> [['a', 1, true], ['b', 2, false]] -// zip(['a'], [1, 2], [true, false]); -> [['a', 1, true], [undefined, 2, false]] + return Array.from({length: arrays.length}, (_, k) => arrays[k][i]); + }) +} +``` + +```js +zip(['a', 'b'], [1, 2], [true, false]); // [['a', 1, true], ['b', 2, false]] +zip(['a'], [1, 2], [true, false]); // [['a', 1, true], [undefined, 2, false]] ``` diff --git a/snippets/zipObject.md b/snippets/zipObject.md index be9172542..99d134ac8 100644 --- a/snippets/zipObject.md +++ b/snippets/zipObject.md @@ -5,7 +5,10 @@ Given an array of valid property identifiers and an array of values, return an o Since an object can have undefined values but not undefined property pointers, the array of properties is used to decide the structure of the resulting object using `Array.reduce()`. ```js -const zipObject = (props, values) => props.reduce((obj, prop, index) => (obj[prop] = values[index], obj), {}); -// zipObject(['a','b','c'], [1,2]) -> {a: 1, b: 2, c: undefined} -// zipObject(['a','b'], [1,2,3]) -> {a: 1, b: 2} +const zipObject = ( props, values ) => props.reduce( ( obj, prop, index ) => ( obj[prop] = values[index], obj ), {} ) +``` + +```js +zipObject(['a','b','c'], [1,2]) // {a: 1, b: 2, c: undefined} +zipObject(['a','b'], [1,2,3]) // {a: 1, b: 2} ```