-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion12.js
61 lines (47 loc) · 1.34 KB
/
question12.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Write a program for swapping of two arrays
var readlineSync = require("readline-sync");
var array1;
var array2;
function inputArrays() {
array1 = [];
array2 = [];
var firstArray = readlineSync.question("Enter first array : ");
var secondArray = readlineSync.question("Enter second array : ");
for (var i = 0; i < firstArray.length; i++) {
array1.push(firstArray[i]);
array2.push(secondArray[i]);
}
console.log("First Array: ", array1);
console.log("Second Array: ", array2);
toSwap();
}
function toSwap() {
var swapQuestion = readlineSync.question("Press enter to swap ");
if (swapQuestion == "") {
swap();
} else {
console.log("just press enter bro.")
toSwap();
}
}
function swap() {
var swp = array1;
array1 = array2;
array2 = swp;
console.log("New First Array: ", array1);
console.log("New Second Array: ", array2);
exit();
}
function exit() {
var exitQuestion = readlineSync.question("Would you like to continue? (Y/n) : ");
if (exitQuestion == "y" || exitQuestion == "Y") {
console.log("here we go again...");
inputArrays();
} else if (exitQuestion == "n") {
console.log("Thank you, Goodbye!");
} else {
console.log("invalid answer, try again.");
exit();
}
}
inputArrays();