Housekeeping, head, tail, init and last of list
This commit is contained in:
@ -5,7 +5,7 @@ If the number of provided arguments (`args`) is sufficient, call the passed func
|
||||
Otherwise return a curried function `f` that expects the rest of the arguments.
|
||||
|
||||
```js
|
||||
curry = f =>
|
||||
var curry = f =>
|
||||
(...args) =>
|
||||
args.length >= f.length ? f(...args) : (...otherArgs) => curry(f)(...args, ...otherArgs)
|
||||
```
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
Use `replace()` to escape special characters.
|
||||
|
||||
```js
|
||||
escapeRegExp = s =>
|
||||
var escapeRegExp = s =>
|
||||
s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
}
|
||||
```
|
||||
|
||||
8
snippets/head-of-list.md
Normal file
8
snippets/head-of-list.md
Normal file
@ -0,0 +1,8 @@
|
||||
### Head of list
|
||||
|
||||
Return `arr[0]`.
|
||||
|
||||
```js
|
||||
var head = arr => arr[0];
|
||||
}
|
||||
```
|
||||
8
snippets/initial-of-list.md
Normal file
8
snippets/initial-of-list.md
Normal file
@ -0,0 +1,8 @@
|
||||
### Initial of list
|
||||
|
||||
Return `arr.slice(0,-1)`.
|
||||
|
||||
```js
|
||||
var initial = arr => arr.slice(0,-1);
|
||||
}
|
||||
```
|
||||
8
snippets/last-of-list.md
Normal file
8
snippets/last-of-list.md
Normal file
@ -0,0 +1,8 @@
|
||||
### Last of list
|
||||
|
||||
Return `arr.slice(-1)[0]`.
|
||||
|
||||
```js
|
||||
var initial = arr => arr.slice(-1)[0];
|
||||
}
|
||||
```
|
||||
8
snippets/tail-of-list.md
Normal file
8
snippets/tail-of-list.md
Normal file
@ -0,0 +1,8 @@
|
||||
### Tail of list
|
||||
|
||||
Return `arr.slice(1)`.
|
||||
|
||||
```js
|
||||
var tail = arr => arr.slice(1);
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user