Capitalize first letter, get current URL
This commit is contained in:
18
README.md
18
README.md
@ -9,7 +9,9 @@
|
||||
## Contents
|
||||
|
||||
* [Anagrams of string (with duplicates)](#anagrams-of-string-with-duplicates)
|
||||
* [Capitalize first letter](#capitalize-first-letter)
|
||||
* [Count occurences of a value in array](#count-occurences-of-a-value-in-array)
|
||||
* [Current URL](#current-url)
|
||||
* [Even or odd number](#even-or-odd-number)
|
||||
* [Fibonacci array generator](#fibonacci-array-generator)
|
||||
* [Greatest common divisor (GCD)](#greatest-common-divisor-gcd)
|
||||
@ -42,6 +44,14 @@ var anagrams = s => {
|
||||
}
|
||||
```
|
||||
|
||||
### Capitalize first letter
|
||||
|
||||
Use `toUpperCase()` to capitalize first letter, `slice(1)` to get the rest of the string.
|
||||
|
||||
```js
|
||||
var capitalize = str => str[0].toUpperCase() + str.slice(1);
|
||||
```
|
||||
|
||||
### Count occurences of a value in array
|
||||
|
||||
Use `filter()` to create an array containing only the items with the specified value, count them using `length`.
|
||||
@ -50,6 +60,14 @@ Use `filter()` to create an array containing only the items with the specified v
|
||||
var countOccurences = (arr, value) => arr.filter(v => v === value).length;
|
||||
```
|
||||
|
||||
### Current URL
|
||||
|
||||
Use `window.location.href` to get current URL.
|
||||
|
||||
```js
|
||||
var currentUrl = _ => window.location.href;
|
||||
```
|
||||
|
||||
### Even or odd number
|
||||
|
||||
Use `Math.abs()` to extend logic to negative numbers, check using the modulo (`%`) operator.
|
||||
|
||||
7
snippets/capitalize-first-letter.md
Normal file
7
snippets/capitalize-first-letter.md
Normal file
@ -0,0 +1,7 @@
|
||||
### Capitalize first letter
|
||||
|
||||
Use `toUpperCase()` to capitalize first letter, `slice(1)` to get the rest of the string.
|
||||
|
||||
```js
|
||||
var capitalize = str => str[0].toUpperCase() + str.slice(1);
|
||||
```
|
||||
7
snippets/current-URL.md
Normal file
7
snippets/current-URL.md
Normal file
@ -0,0 +1,7 @@
|
||||
### Current URL
|
||||
|
||||
Use `window.location.href` to get current URL.
|
||||
|
||||
```js
|
||||
var currentUrl = _ => window.location.href;
|
||||
```
|
||||
Reference in New Issue
Block a user