From b995e1bea1a7b88f2ed8e130f3423fb4134366a4 Mon Sep 17 00:00:00 2001 From: piyuesh Date: Wed, 13 Dec 2017 17:41:45 +0530 Subject: [PATCH] prefixed Array. to reduce(), sort(), map() methods in snippets. --- snippets/URL-parameters.md | 2 +- snippets/anagrams-of-string-(with-duplicates).md | 2 +- snippets/average-of-array-of-numbers.md | 2 +- snippets/count-occurrences-of-a-value-in-array.md | 2 +- snippets/deep-flatten-array.md | 2 +- snippets/flatten-array.md | 2 +- snippets/initialize-array-with-range.md | 2 +- snippets/powerset.md | 2 +- snippets/randomize-order-of-array.md | 2 +- snippets/sort-characters-in-string-(alphabetical).md | 2 +- snippets/sum-of-array-of-numbers.md | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/snippets/URL-parameters.md b/snippets/URL-parameters.md index 4620513dc..b3b676931 100644 --- a/snippets/URL-parameters.md +++ b/snippets/URL-parameters.md @@ -1,6 +1,6 @@ ### URL parameters -Use `match()` with an appropriate regular expression to get all key-value pairs, `map()` them appropriately. +Use `match()` with an appropriate regular expression to get all key-value pairs, `Array.map()` them appropriately. Combine all key-value pairs into a single object using `Object.assign()` and the spread operator (`...`). Pass `location.search` as the argument to apply to the current `url`. diff --git a/snippets/anagrams-of-string-(with-duplicates).md b/snippets/anagrams-of-string-(with-duplicates).md index 10b949654..7e1d613b6 100644 --- a/snippets/anagrams-of-string-(with-duplicates).md +++ b/snippets/anagrams-of-string-(with-duplicates).md @@ -2,7 +2,7 @@ Use recursion. For each letter in the given string, create all the partial anagrams for the rest of its letters. -Use `map()` to combine the letter with each partial anagram, then `reduce()` to combine all anagrams in one array. +Use `Array.map()` to combine the letter with each partial anagram, then `Array.reduce()` to combine all anagrams in one array. Base cases are for string `length` equal to `2` or `1`. ```js diff --git a/snippets/average-of-array-of-numbers.md b/snippets/average-of-array-of-numbers.md index 615e183b8..8d9aaf1cd 100644 --- a/snippets/average-of-array-of-numbers.md +++ b/snippets/average-of-array-of-numbers.md @@ -1,6 +1,6 @@ ### Average of array of numbers -Use `reduce()` to add each value to an accumulator, initialized with a value of `0`, divide by the `length` of the array. +Use `Array.reduce()` to add each value to an accumulator, initialized with a value of `0`, divide by the `length` of the array. ```js const average = arr => diff --git a/snippets/count-occurrences-of-a-value-in-array.md b/snippets/count-occurrences-of-a-value-in-array.md index 89e3b5b6d..f4a0dc210 100644 --- a/snippets/count-occurrences-of-a-value-in-array.md +++ b/snippets/count-occurrences-of-a-value-in-array.md @@ -1,6 +1,6 @@ ### Count occurrences of a value in array -Use `reduce()` to increment a counter each time you encounter the specific value inside the array. +Use `Array.reduce()` to increment a counter each time you encounter the specific value inside the array. ```js const countOccurrences = (arr, value) => arr.reduce((a, v) => v === value ? a + 1 : a + 0, 0); diff --git a/snippets/deep-flatten-array.md b/snippets/deep-flatten-array.md index 472143583..397d62241 100644 --- a/snippets/deep-flatten-array.md +++ b/snippets/deep-flatten-array.md @@ -1,7 +1,7 @@ ### Deep flatten array Use recursion. -Use `reduce()` to get all elements that are not arrays, flatten each element that is an array. +Use `Array.reduce()` to get all elements that are not arrays, flatten each element that is an array. ```js const deepFlatten = arr => diff --git a/snippets/flatten-array.md b/snippets/flatten-array.md index a677fa4ea..224060d02 100644 --- a/snippets/flatten-array.md +++ b/snippets/flatten-array.md @@ -1,6 +1,6 @@ ### Flatten array -Use `reduce()` to get all elements inside the array and `concat()` to flatten them. +Use `Array.reduce()` to get all elements inside the array and `concat()` to flatten them. ```js const flatten = arr => arr.reduce( (a, v) => a.concat(v), []); diff --git a/snippets/initialize-array-with-range.md b/snippets/initialize-array-with-range.md index c974f2786..03de99eb2 100644 --- a/snippets/initialize-array-with-range.md +++ b/snippets/initialize-array-with-range.md @@ -1,6 +1,6 @@ ### Initialize array with range -Use `Array(end-start)` to create an array of the desired length, `map()` to fill with the desired values in a range. +Use `Array(end-start)` to create an array of the desired length, `Array.map()` to fill with the desired values in a range. You can omit `start` to use a default value of `0`. ```js diff --git a/snippets/powerset.md b/snippets/powerset.md index 2908c78b2..62ec96655 100644 --- a/snippets/powerset.md +++ b/snippets/powerset.md @@ -1,6 +1,6 @@ ### Powerset -Use `reduce()` combined with `map()` to iterate over elements and combine into an array containing all combinations. +Use `Array.reduce()` combined with `Array.map()` to iterate over elements and combine into an array containing all combinations. ```js const powerset = arr => diff --git a/snippets/randomize-order-of-array.md b/snippets/randomize-order-of-array.md index fe9093843..d65aaf444 100644 --- a/snippets/randomize-order-of-array.md +++ b/snippets/randomize-order-of-array.md @@ -1,6 +1,6 @@ ### Randomize order of array -Use `sort()` to reorder elements, utilizing `Math.random()` to randomize the sorting. +Use `Array.sort()` to reorder elements, utilizing `Math.random()` to randomize the sorting. ```js const randomizeOrder = arr => arr.sort( (a,b) => Math.random() >= 0.5 ? -1 : 1); diff --git a/snippets/sort-characters-in-string-(alphabetical).md b/snippets/sort-characters-in-string-(alphabetical).md index c283ca17c..7ed73cb14 100644 --- a/snippets/sort-characters-in-string-(alphabetical).md +++ b/snippets/sort-characters-in-string-(alphabetical).md @@ -1,6 +1,6 @@ ### Sort characters in string (alphabetical) -Split the string using `split('')`, `sort()` utilizing `localeCompare()`, recombine using `join('')`. +Split the string using `split('')`, `Array.sort()` utilizing `localeCompare()`, recombine using `join('')`. ```js const sortCharactersInString = str => diff --git a/snippets/sum-of-array-of-numbers.md b/snippets/sum-of-array-of-numbers.md index fcf01949c..939106cc1 100644 --- a/snippets/sum-of-array-of-numbers.md +++ b/snippets/sum-of-array-of-numbers.md @@ -1,6 +1,6 @@ ### Sum of array of numbers -Use `reduce()` to add each value to an accumulator, initialized with a value of `0`. +Use `Array.reduce()` to add each value to an accumulator, initialized with a value of `0`. ```js const sum = arr => arr.reduce( (acc , val) => acc + val, 0);