-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04-includes.js
More file actions
69 lines (50 loc) · 1.31 KB
/
04-includes.js
File metadata and controls
69 lines (50 loc) · 1.31 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
58
59
60
61
62
63
64
65
66
67
68
69
/**
Given an array (myArray) and the value (val).
Write a JS program to find whether an array (myArray) includes the given value (val) or not using the array method "includes".
Input
The first line of input will contain an array (myArray).
The second line of input will contain any value.
Output
The output should be a single line containing the boolean value.
Constraints
Strings should be given in quotes.
Sample Input 1
[3, 4, 5]
4
Sample Output 1
true
Sample Input 2
[9.8, 'Hello', true] Hi'
Sample Output 2
false
*/
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString
.trim()
.split("\n")
.map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
/* Please do not modify anything above this line */
function isValuePresent(myArray, val) {
let result = myArray.includes(val);
return result;
}
/* Please do not modify anything below this line */
function main() {
let myArray = JSON.parse(readLine().replace(/'/g, '"'));
let val = JSON.parse(readLine().replace(/'/g, '"'));
let isPresent = isValuePresent(myArray, val);
console.log(isPresent);
}