Merge pull request #75 from meetzaveri/patch-2
Create join_array_like_objects.md
This commit is contained in:
8
snippets/check-for-boolean-primitive-values.md
Normal file
8
snippets/check-for-boolean-primitive-values.md
Normal 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
|
||||||
|
```
|
||||||
12
snippets/drop-elements-in-array.md
Normal file
12
snippets/drop-elements-in-array.md
Normal 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]
|
||||||
|
```
|
||||||
11
snippets/join_array_like_objects.md
Normal file
11
snippets/join_array_like_objects.md
Normal 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);
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user