Add nodeListToArray
This commit is contained in:
13
snippets/nodeListToArray.md
Normal file
13
snippets/nodeListToArray.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
### nodeListToArray
|
||||||
|
|
||||||
|
Converts a `NodeList` to an array.
|
||||||
|
|
||||||
|
Use `Array.prototype.slice()` and `Function.prototype.call()` to convert a `NodeList` to an array.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const nodeListToArray = nodeList => Array.prototype.slice.call(nodeList);
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
nodeListToArray(document.childNodes); // [ <!DOCTYPE html>, html ]
|
||||||
|
```
|
||||||
@ -168,6 +168,7 @@ minN:array,math
|
|||||||
mostPerformant:utility,function
|
mostPerformant:utility,function
|
||||||
negate:function
|
negate:function
|
||||||
nest:object
|
nest:object
|
||||||
|
nodeListToArray:browser,array
|
||||||
none:array,function
|
none:array,function
|
||||||
nthArg:utility,function
|
nthArg:utility,function
|
||||||
nthElement:array
|
nthElement:array
|
||||||
|
|||||||
2
test/nodeListToArray/nodeListToArray.js
Normal file
2
test/nodeListToArray/nodeListToArray.js
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
const nodeListToArray = nodeList => Array.prototype.slice.call(nodeList);
|
||||||
|
module.exports = nodeListToArray;
|
||||||
13
test/nodeListToArray/nodeListToArray.test.js
Normal file
13
test/nodeListToArray/nodeListToArray.test.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
const nodeListToArray = require('./nodeListToArray.js');
|
||||||
|
|
||||||
|
test('Testing nodeListToArray', (t) => {
|
||||||
|
//For more information on all the methods supported by tape
|
||||||
|
//Please go to https://github.com/substack/tape
|
||||||
|
t.true(typeof nodeListToArray === 'function', 'nodeListToArray is a Function');
|
||||||
|
//t.deepEqual(nodeListToArray(args..), 'Expected');
|
||||||
|
//t.equal(nodeListToArray(args..), 'Expected');
|
||||||
|
//t.false(nodeListToArray(args..), 'Expected');
|
||||||
|
//t.throws(nodeListToArray(args..), 'Expected');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
14
test/testlog
14
test/testlog
@ -1,4 +1,4 @@
|
|||||||
Test log for: Sun May 06 2018 17:55:09 GMT+0300 (GTB Daylight Time)
|
Test log for: Sun May 06 2018 18:11:06 GMT+0300 (GTB Daylight Time)
|
||||||
|
|
||||||
> 30-seconds-of-code@0.0.3 test H:\My Files\git Repositories\30-seconds-of-code
|
> 30-seconds-of-code@0.0.3 test H:\My Files\git Repositories\30-seconds-of-code
|
||||||
> tape test/**/*.test.js | tap-spec
|
> tape test/**/*.test.js | tap-spec
|
||||||
@ -1135,6 +1135,10 @@ Test log for: Sun May 06 2018 17:55:09 GMT+0300 (GTB Daylight Time)
|
|||||||
|
|
||||||
√ nest is a Function
|
√ nest is a Function
|
||||||
|
|
||||||
|
Testing nodeListToArray
|
||||||
|
|
||||||
|
√ nodeListToArray is a Function
|
||||||
|
|
||||||
Testing none
|
Testing none
|
||||||
|
|
||||||
√ none is a Function
|
√ none is a Function
|
||||||
@ -2002,16 +2006,16 @@ Test log for: Sun May 06 2018 17:55:09 GMT+0300 (GTB Daylight Time)
|
|||||||
Testing zipWith
|
Testing zipWith
|
||||||
|
|
||||||
√ zipWith is a Function
|
√ zipWith is a Function
|
||||||
√ Runs the function provided
|
|
||||||
√ Sends a GET request
|
√ Sends a GET request
|
||||||
|
√ Runs the function provided
|
||||||
√ Runs promises in series
|
√ Runs promises in series
|
||||||
√ Sends a POST request
|
√ Sends a POST request
|
||||||
√ Works as expecting, passing arguments properly
|
√ Works as expecting, passing arguments properly
|
||||||
√ Works with multiple promises
|
√ Works with multiple promises
|
||||||
|
|
||||||
|
|
||||||
total: 1018
|
total: 1019
|
||||||
passing: 1018
|
passing: 1019
|
||||||
duration: 2.7s
|
duration: 2.5s
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user