Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
46
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.  
  7.  
  8.  
  9. /* From here down, you are not expected to
  10. understand.... for now :)
  11.  
  12.  
  13. Nothing to see here!
  14.  
  15. */
  16.  
  17.  
  18. // tests
  19.  
  20. function testAddToList() {
  21.  
  22. const input1 = ["red", "blue", "green"];
  23. const input2 = "pink";
  24. const expected = ["red", "blue", "green", "pink"];
  25. const result = addToList(input1, input2);
  26.  
  27. if (
  28. result && result.length && expected.length === result.length &&
  29. expected.every(function(item) {
  30. return result.indexOf(item) > -1;
  31. })) {
  32. console.log('SUCCESS: `addToList` works!');
  33. } else {
  34. console.error('FAILURE: `addToList` is not working');
  35. }
  36. }
  37.  
  38. testAddToList();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement