Guest User

Untitled

a guest
Jun 15th, 2020
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. function applyPredicate(elements, predicate) {
  2. const test = [];
  3. elements.forEach(el => predicate(el) ? test.push(el) : '');
  4. return test;
  5. }
  6.  
  7. /* Weryfikacja */
  8.  
  9. function verify(input, goal) {
  10. const inputAsString = JSON.stringify(input);
  11. const goalAsString = JSON.stringify(goal);
  12. console.log(input);
  13. console.log(goal);
  14. if (inputAsString === goalAsString) {
  15. console.log('Gratulacje!');
  16. } else {
  17. console.log(`Niestety, oczekiwano - ${goalAsString}, otrzymano - ${inputAsString}`);
  18. }
  19. }
  20.  
  21. verify(applyPredicate([1, 2, 3], element => element > 2), [3]);
  22. verify(applyPredicate(['a', 'b', 'c'], element => ['b', 'c'].includes(element)), ['b', 'c']);
  23. verify(applyPredicate(['x', 'y'], element => element === 'z'), []);
Add Comment
Please, Sign In to add comment