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) * [`isAnagram`](#isanagram)
* [`isLowerCase`](#islowercase) * [`isLowerCase`](#islowercase)
* [`isUpperCase`](#isuppercase) * [`isUpperCase`](#isuppercase)
* [`mapString`](#mapstring)
* [`mask`](#mask) * [`mask`](#mask)
* [`pad`](#pad) * [`pad`](#pad)
* [`palindrome`](#palindrome) * [`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`. 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. 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) => const dig = (obj, target) =>
target in obj target in obj
? obj[target] ? obj[target]
: Object : Object.values(obj).reduce((acc, val) => {
.values(obj)
.reduce((acc, val) => {
if (acc !== undefined) return acc; if (acc !== undefined) return acc;
if (typeof val === 'object') return dig(val, target); if (typeof val === 'object') return dig(val, target);
}, undefined); }, undefined);
``` ```
``` <details>
<summary>Examples</summary>
```js
const data = { const data = {
level1: { level1: {
level2: { level2: {
@ -6399,9 +6401,6 @@ const data = {
}; };
dig(data, 'level3'); // 'some data' dig(data, 'level3'); // 'some data'
dig(data, 'level4'); // undefined dig(data, 'level4'); // undefined
```<details>
<summary>Examples</summary>
``` ```
</details> </details>
@ -7609,6 +7608,34 @@ isLowerCase('aB4'); // false
<br>[⬆ Back to top](#table-of-contents) <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 ### mask
Replaces all but the last `num` of characters with the specified mask character. 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) => const dig = (obj, target) =>
target in obj target in obj
? obj[target] ? obj[target]
: Object : Object.values(obj).reduce((acc, val) => {
.values(obj)
.reduce((acc, val) => {
if (acc !== undefined) return acc; if (acc !== undefined) return acc;
if (typeof val === 'object') return dig(val, target); if (typeof val === 'object') return dig(val, target);
}, undefined); }, undefined);

View File

@ -8,7 +8,10 @@ The callback function, `fn`, takes three arguments (the current character, the i
```js ```js
const mapString = (str, fn) => 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 ```js