Update drop, add dropWhile, dropRightWhile

This commit is contained in:
Angelos Chalaris
2018-01-26 12:23:18 +02:00
parent 49b1fc7947
commit aea334a94a
14 changed files with 65 additions and 31 deletions

View File

@ -1,5 +1,5 @@
const dropElements = (arr, func) => {
const dropWhile = (arr, func) => {
while (arr.length > 0 && !func(arr[0])) arr = arr.slice(1);
return arr;
};
module.exports = dropElements
module.exports = dropWhile

View File

@ -1,14 +1,14 @@
const test = require('tape');
const dropElements = require('./dropElements.js');
const dropWhile = require('./dropWhile.js');
test('Testing dropElements', (t) => {
test('Testing dropWhile', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof dropElements === 'function', 'dropElements is a Function');
t.deepEqual(dropElements([1, 2, 3, 4], n => n >= 3), [3,4], "Removes elements in an array until the passed function returns true");
//t.deepEqual(dropElements(args..), 'Expected');
//t.equal(dropElements(args..), 'Expected');
//t.false(dropElements(args..), 'Expected');
//t.throws(dropElements(args..), 'Expected');
t.true(typeof dropWhile === 'function', 'dropWhile is a Function');
t.deepEqual(dropWhile([1, 2, 3, 4], n => n >= 3), [3,4], "Removes elements in an array until the passed function returns true");
//t.deepEqual(dropWhile(args..), 'Expected');
//t.equal(dropWhile(args..), 'Expected');
//t.false(dropWhile(args..), 'Expected');
//t.throws(dropWhile(args..), 'Expected');
t.end();
});

View File

@ -252,9 +252,9 @@ Test log for: Fri Jan 26 2018 12:00:18 GMT+0200 (GTB Standard Time)
√ distance is a Function
Testing dropElements
Testing dropWhile
√ dropElements is a Function
√ dropWhile is a Function
√ Removes elements in an array until the passed function returns true
Testing dropRight