Travis build: 78

This commit is contained in:
30secondsofcode
2018-07-14 08:01:07 +00:00
parent 005dfcf8d0
commit 855b6d70d5
14 changed files with 83 additions and 51 deletions

View File

@ -406,6 +406,7 @@ average(1, 2, 3);
* [`isAnagram`](#isanagram)
* [`isLowerCase`](#islowercase)
* [`isUpperCase`](#isuppercase)
* [`mapString`](#mapstring)
* [`mask`](#mask)
* [`pad`](#pad)
* [`palindrome`](#palindrome)
@ -6377,19 +6378,20 @@ 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) => {
: 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: {
@ -6399,9 +6401,6 @@ const 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.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -9,9 +9,7 @@ If found, return the value of `obj[target]`, otherwise use `Object.values(obj)`
const dig = (obj, target) =>
target in obj
? obj[target]
: Object
.values(obj)
.reduce((acc, val) => {
: Object.values(obj).reduce((acc, val) => {
if (acc !== undefined) return acc;
if (typeof val === 'object') return dig(val, target);
}, undefined);

View File

@ -8,7 +8,10 @@ The callback function, `fn`, takes three arguments (the current character, the i
```js
const mapString = (str, fn) =>
str.split('').map((c, i) => fn(c, i, str)).join('');
str
.split('')
.map((c, i) => fn(c, i, str))
.join('');
```
```js