Merge pull request #75 from meetzaveri/patch-2

Create join_array_like_objects.md
This commit is contained in:
Angelos Chalaris
2017-12-14 12:48:26 +02:00
committed by GitHub
3 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,8 @@
### Check for boolean primitive values
Use `typeof` to check if a value is classified as a boolean primitive.
```js
const isBool = val => typeof val === 'boolean';
// isBool(null) -> false
```

View File

@ -0,0 +1,12 @@
### Drop elements in array
Loop through the array, using `Array.shift()` to drop the first element of the array until the returned value from the function is `true`.
Returns the remaining elements.
```js
const dropElements = (arr,func) => {
while(arr.length > 0 && !func(arr[0])) arr.shift();
return arr;
}
// dropElements([1, 2, 3, 4], n => n >= 3) -> [3,4]
```

View File

@ -0,0 +1,11 @@
### Joining an array-like object
The following example joins array-like object (arguments), by calling Function.prototype.call on Array.prototype.join.
```
function f(a, b, c) {
var s = Array.prototype.join.call(arguments);
console.log(s); // '1,a,true'
}
f(1, 'a', true);
```