Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Завдання: https://shpp.gitbook.io/zero/tutorials/functions/array-reversing
- function main () {
- let p = +prompt("Розмір масиву ?");
- let m = [p];
- oll(p, m);
- printmassiv(m);
- rever(m);
- // написати "ось реверснутий масив:"
- // вивестиНаЕкранКрасивоМасив(м)
- }
- function oll (p, m) {
- for (let x = 0; x < p; x++) {
- m[x] = prompt("?");
- }
- }
- function printmassiv (m) {
- console.put("[");
- for (let x = 0; m[x] != undefined; x++) {
- console.put(m[x]);
- if (m[x + 1] != undefined) {
- console.put(",");
- }
- }
- console.put("]");
- console.log();
- }
- function rever (m) {
- let n = [];
- let g;
- for (let x = 0; m[x] != undefined; x++) {
- n[x] = m[x];
- }
- for (let x = 0, y = n.length - 1; x < n.length; x++, y--) {
- g = n[x];
- n[x] = n[y];
- n[y] = g;
- }
- printmassiv(n);
- }
- main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement