Advertisement
kstoyanov

02. Print every N-th Element from an Array v1

Sep 18th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(args) {
  2.   const step = Number(args.pop());
  3.  
  4.   const newItems = [];
  5.  
  6.   const getELement = (arg1) => {
  7.     for (let i = 0; i < arg1.length; i += step) {
  8.       newItems.push(args[i]);
  9.     }
  10.   };
  11.  
  12.   getELement(args);
  13.  
  14.   console.log(newItems.join('\n'));
  15.  
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement