Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. // 1
  2. function makeList(item1, item2, item3) {
  3. return [item1, item2, item3];
  4. }
  5.  
  6. //2
  7. function addToList(list, item) {
  8. list.push(item);
  9. return list;
  10. }
  11.  
  12. //3
  13. function accessFirstItem(array) {
  14. return array[0]
  15. }
  16.  
  17. function accessThirdItem(array) {
  18. return array[2]
  19. }
  20.  
  21. //4
  22. function firstFourItems(array) {
  23. return array.slice(0,4);
  24. }
  25.  
  26. function lastThreeItems(array) {
  27. return array.slice(-3);
  28. }
  29.  
  30. //5
  31. function minusLastItem(array) {
  32. return array.slice(0,-1)
  33. }
  34.  
  35. function copyFirstHalf(array) {
  36. return array.slice(0, array.length/2);
  37.  
  38. }
  39.  
  40. //6
  41.  
  42. function squares(array) {
  43. return array.map(num => num * num);
  44. }
  45.  
  46. //7
  47. function greatestToLeast(array) {
  48. return array.sort(function(a,b) {
  49. return b - a;
  50. } );
  51. }
  52.  
  53. //8
  54. function shortWords(array) {
  55. return array.filter(item => item.length < 5);
  56. }
  57.  
  58. //9
  59. function divisibleBy5(array) {
  60. return array.find(num => num % 5 === 0);
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement