Build README

This commit is contained in:
Angelos Chalaris
2017-12-12 16:24:33 +02:00
parent efcd35a210
commit b7b9e9476e

View File

@ -12,6 +12,7 @@
* [Average of array of numbers](#average-of-array-of-numbers)
* [Capitalize first letter of every word](#capitalize-first-letter-of-every-word)
* [Capitalize first letter](#capitalize-first-letter)
* [Check_for_palindrome](#check_for_palindrome)
* [Count occurrences of a value in array](#count-occurrences-of-a-value-in-array)
* [Current URL](#current-url)
* [Curry](#curry)
@ -93,6 +94,15 @@ const capitalize = (str, lowerRest = false) =>
str.slice(0, 1).toUpperCase() + (lowerRest? str.slice(1).toLowerCase() : str.slice(1));
```
### Check for palindrome
Convert string `toLowerCase()` and use `replace()` to remove non-alphanumeric characters from it.
Then, `split('')` into individual characters, `reverse()`, `join('')` and compare to the original, unreversed string, after converting it `tolowerCase()`.
```
palindrome = str => (str.toLowerCase().replace(/[\W_]/g,'').split('').reverse().join('')==str.toLowerCase().replace(/[\W_]/g,''));
```
### Count occurrences of a value in array
Use `reduce()` to increment a counter each time you encounter the specific value inside the array.