Guest User

Untitled

a guest
Feb 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. function addToList(list, item) {
  2. list.push(item);
  3. return(list);
  4. }
  5.  
  6. /* From here down, you are not expected to
  7. understand.... for now :)
  8.  
  9.  
  10. Nothing to see here!
  11.  
  12. */
  13.  
  14. // tests
  15.  
  16. function testAddToList() {
  17. const input1 = ['red', 'blue', 'green'];
  18. const input2 = 'pink';
  19. const expected = ['red', 'blue', 'green', 'pink'];
  20. const result = addToList(input1, input2);
  21.  
  22. if (
  23. result &&
  24. result.length &&
  25. expected.length === result.length &&
  26. expected.every(function(item) {
  27. return result.indexOf(item) > -1;
  28. })
  29. ) {
  30. console.log('SUCCESS: `addToList` works!');
  31. } else {
  32. console.error('FAILURE: `addToList` is not working');
  33. }
  34. }
  35.  
  36. testAddToList();
Add Comment
Please, Sign In to add comment