Advertisement
Spocoman

03. Reverse an Array of Numbers

Jan 20th, 2022
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(num, arr) {
  2.  
  3.     let print = "";
  4.     for (let i = num - 1; i >= 0; i--){
  5.         print += `${arr[i]} `;
  6.     }
  7.     console.log(print);
  8. }
  9.  
  10.  
  11. Решение със slice(), reverse() и join():
  12.  
  13. function solve(num, arr) {
  14.  
  15.     let reverseArr = arr.slice(0, num).reverse();
  16.     console.log(reverseArr.join(' '));
  17.  
  18. }
  19.  
  20. Или тарикатската:)
  21.  
  22. function solve(num, arr) {
  23.  
  24.     console.log(arr.slice(0, num).reverse().join(' '));
  25.  
  26. }
  27.  
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement