Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function applyPredicate(elements, predicate) {
- const test = [];
- elements.forEach(el => predicate(el) ? test.push(el) : '');
- return test;
- }
- /* Weryfikacja */
- function verify(input, goal) {
- const inputAsString = JSON.stringify(input);
- const goalAsString = JSON.stringify(goal);
- console.log(input);
- console.log(goal);
- if (inputAsString === goalAsString) {
- console.log('Gratulacje!');
- } else {
- console.log(`Niestety, oczekiwano - ${goalAsString}, otrzymano - ${inputAsString}`);
- }
- }
- verify(applyPredicate([1, 2, 3], element => element > 2), [3]);
- verify(applyPredicate(['a', 'b', 'c'], element => ['b', 'c'].includes(element)), ['b', 'c']);
- verify(applyPredicate(['x', 'y'], element => element === 'z'), []);
Add Comment
Please, Sign In to add comment