Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. /**
  2. * Filters out first 'n' elements from the list
  3. */
  4.  
  5. /**
  6. * Represents a array
  7. */
  8. var list = [ 1, 2, 3, 4, 5, 6, 7, 6, 3, 4, 5, 12, 123, 2, 2, 23, 4, 5, 67, 4, 2, 34, 23, 34, 5, 45];
  9.  
  10.  
  11. /**
  12. * Represents a filterArray method.
  13. * @ constructor
  14. * @param {array} arrayItem - An array containing some elements
  15. */
  16. function filterArray(arrayItem) {
  17. var list = []
  18. var n = 20;
  19. for(i = 0; i < n ; i++) {
  20. if (arrayItem[i] < n ) {
  21. list.push(arrayItem[i])
  22. }
  23. }
  24. return list
  25. }
  26.  
  27. /**
  28. * Call the function and pass an array
  29. * @param {list}
  30. */
  31. filterArray(list)
  32.  
  33. // [1, 2, 3, 4, 5, 6, 7, 6, 3, 4, 5, 12, 123, 2, 2, 23, 4, 5, 67, 4]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement