Build README, resolve #62

This commit is contained in:
Angelos Chalaris
2017-12-13 14:49:56 +02:00
parent 5ad246b566
commit 231ae4e57d

View File

@ -73,7 +73,7 @@
Use recursion. Use recursion.
For each letter in the given string, create all the partial anagrams for the rest of its letters. 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`. Base cases are for string `length` equal to `2` or `1`.
```js ```js
@ -87,7 +87,7 @@ const anagrams = str => {
### Average of array of numbers ### 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 ```js
const average = arr => const average = arr =>
@ -165,7 +165,7 @@ const chunk = (arr, size) =>
### Count occurrences of a value in array ### 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 ```js
const countOccurrences = (arr, value) => arr.reduce((a, v) => v === value ? a + 1 : a + 0, 0); const countOccurrences = (arr, value) => arr.reduce((a, v) => v === value ? a + 1 : a + 0, 0);
@ -203,7 +203,7 @@ const curry = (f, arity = f.length, next) =>
### Deep flatten array ### Deep flatten array
Use recursion. 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 ```js
const deepFlatten = arr => const deepFlatten = arr =>
@ -290,7 +290,7 @@ const unique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexOf(i));
### Flatten array ### 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 ```js
const flatten = arr => arr.reduce( (a, v) => a.concat(v), []); const flatten = arr => arr.reduce( (a, v) => a.concat(v), []);
@ -379,7 +379,7 @@ const initial = arr => arr.slice(0,-1);
### Initialize array with range ### 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`. You can omit `start` to use a default value of `0`.
```js ```js
@ -466,7 +466,7 @@ const pipe = (...funcs) => arg => funcs.reduce((acc, func) => func(acc), arg);
### Powerset ### 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 ```js
const powerset = arr => const powerset = arr =>
@ -512,7 +512,7 @@ const randomInRange = (min, max) => Math.random() * (max - min) + min;
### Randomize order of array ### 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 ```js
const randomizeOrder = arr => arr.sort( (a,b) => Math.random() >= 0.5 ? -1 : 1); const randomizeOrder = arr => arr.sort( (a,b) => Math.random() >= 0.5 ? -1 : 1);
@ -599,7 +599,7 @@ const similarity = (arr, values) => arr.filter(v => values.includes(v));
### Sort characters in string (alphabetical) ### 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 ```js
const sortCharactersInString = str => const sortCharactersInString = str =>
@ -609,7 +609,7 @@ const sortCharactersInString = str =>
### Sum of array of numbers ### 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 ```js
const sum = arr => arr.reduce( (acc , val) => acc + val, 0); const sum = arr => arr.reduce( (acc , val) => acc + val, 0);