Advertisement
Guest User

Untitled

a guest
May 24th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. function print(arr, callback) {
  2. for (var i = 0; i < arr.length; i++) {
  3. callback(arr[i], i);
  4. }
  5. }
  6.  
  7. function printElement(el) {
  8. console.log(el);
  9. }
  10.  
  11. function printIndexAndElement(el, index) {
  12. console.log(index + " => " + el);
  13. }
  14.  
  15. function printIndexAndIncrementElement(el, index) {
  16. console.log(index + " => " + (el + 2));
  17. }
  18.  
  19. var numbers = [3, 5, 1];
  20. print(numbers, printElement);
  21. print(numbers, printIndexAndElement);
  22. print(numbers, printIndexAndIncrementElement);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement