Advertisement
Viktor_Profa

Untitled

Feb 10th, 2023
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. // Завдання: https://shpp.gitbook.io/zero/tutorials/functions/array-reversing
  2.  
  3. function main () {
  4. let p = +prompt("Розмір масиву ?");
  5. let m = [p];
  6.  
  7. oll(p, m);
  8. printmassiv(m);
  9. rever(m);
  10. // написати "ось реверснутий масив:"
  11. // вивестиНаЕкранКрасивоМасив(м)
  12. }
  13.  
  14. function oll (p, m) {
  15. for (let x = 0; x < p; x++) {
  16. m[x] = prompt("?");
  17. }
  18. }
  19.  
  20. function printmassiv (m) {
  21. console.put("[");
  22.  
  23. for (let x = 0; m[x] != undefined; x++) {
  24. console.put(m[x]);
  25.  
  26. if (m[x + 1] != undefined) {
  27. console.put(",");
  28. }
  29. }
  30.  
  31. console.put("]");
  32. console.log();
  33. }
  34.  
  35. function rever (m) {
  36. let n = [];
  37. let g;
  38.  
  39. for (let x = 0; m[x] != undefined; x++) {
  40. n[x] = m[x];
  41. }
  42.  
  43. for (let x = 0, y = n.length - 1; x < n.length; x++, y--) {
  44. g = n[x];
  45. n[x] = n[y];
  46. n[y] = g;
  47. }
  48.  
  49. printmassiv(n);
  50. }
  51.  
  52. main();
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement