Travis build: 78
This commit is contained in:
53
README.md
53
README.md
@ -406,6 +406,7 @@ average(1, 2, 3);
|
||||
* [`isAnagram`](#isanagram)
|
||||
* [`isLowerCase`](#islowercase)
|
||||
* [`isUpperCase`](#isuppercase)
|
||||
* [`mapString`](#mapstring)
|
||||
* [`mask`](#mask)
|
||||
* [`pad`](#pad)
|
||||
* [`palindrome`](#palindrome)
|
||||
@ -6377,31 +6378,29 @@ Returns the target value in a nested JSON object, based on the given key.
|
||||
Use the `in` operator to check if `target` exists in `obj`.
|
||||
If found, return the value of `obj[target]`, otherwise use `Object.values(obj)` and `Array.reduce()` to recursively call `dig` on each nested object until the first matching key/value pair is found.
|
||||
|
||||
```
|
||||
```js
|
||||
const dig = (obj, target) =>
|
||||
target in obj
|
||||
? obj[target]
|
||||
: Object
|
||||
.values(obj)
|
||||
.reduce((acc, val) => {
|
||||
if (acc !== undefined) return acc;
|
||||
if (typeof val === 'object') return dig(val, target);
|
||||
}, undefined);
|
||||
: Object.values(obj).reduce((acc, val) => {
|
||||
if (acc !== undefined) return acc;
|
||||
if (typeof val === 'object') return dig(val, target);
|
||||
}, undefined);
|
||||
```
|
||||
|
||||
```
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
const data = {
|
||||
level1:{
|
||||
level2:{
|
||||
level1: {
|
||||
level2: {
|
||||
level3: 'some data'
|
||||
}
|
||||
}
|
||||
};
|
||||
dig(data, 'level3'); // 'some data'
|
||||
dig(data, 'level4'); // undefined
|
||||
```<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```
|
||||
|
||||
</details>
|
||||
@ -7609,6 +7608,34 @@ isLowerCase('aB4'); // false
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### mapString
|
||||
|
||||
Creates a new string with the results of calling a provided function on every character in the calling string.
|
||||
|
||||
Use `String.split('')` and `Array.map()` to call the provided function, `fn`, for each character in `str`.
|
||||
Use `Array.join('')` to recombine the array of characters into a string.
|
||||
The callback function, `fn`, takes three arguments (the current character, the index of the current character and the string `mapString` was called upon).
|
||||
|
||||
```js
|
||||
const mapString = (str, fn) =>
|
||||
str
|
||||
.split('')
|
||||
.map((c, i) => fn(c, i, str))
|
||||
.join('');
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
mapString('lorem ipsum', c => c.toUpperCase()); // 'LOREM IPSUM'
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### mask
|
||||
|
||||
Replaces all but the last `num` of characters with the specified mask character.
|
||||
|
||||
Reference in New Issue
Block a user