-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
57 lines (50 loc) · 1.47 KB
/
script.js
File metadata and controls
57 lines (50 loc) · 1.47 KB
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
"use strict";
const readline = require("readline");
let rl;
function createIOStream(){
rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
}
let arr1 = [];
let arr2 = [];
// let arr1 = ["test", "service2", "dev", "service4", "test5", "test6", "test7", "service8", "prod"];
// let arr2 = ["test6", "service2", "service4", "service8"];
function isEnd(input, array){
if (input === "end") {
console.log(array);
rl.close();
return true;
}
}
function workOnArrays(array1, array2){
console.log("Enter some words, type 'end' to finish array filling.");
createIOStream();
console.log("first array:");
rl.on("line", (input) => {
if(isEnd(input, array1)){
createIOStream();
console.log("second array:");
rl.on("line", (input) => {
if(isEnd(input, array2)){
arrayComparison(array1, array2);
} else array2.push(input);
});
} else array1.push(input);
});
}
function arrayComparison(array1, array2){
let resultString = "";
for (let i = 0; i < array1.length; i++) {
let temp = 0;
for (let j = 0; j < array2.length; j++) {
if(array1[i] === array2[j]){
temp = 1;
}
}
resultString += temp;
}
console.log(resultString);
}
workOnArrays(arr1, arr2);