-
Notifications
You must be signed in to change notification settings - Fork 0
/
depositBoxes.js
84 lines (66 loc) · 2.06 KB
/
depositBoxes.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
Medium Level - 02 Problem
Safety Deposit Boxes
You are robbing a bank, but you’re not taking everything. You are looking for a specific item in the safety deposit
boxes and you are going to drill into each one in order to find your item. Once you find your item you can make your escape,
but how long will it take you to get to that item?
Task
Determine the amount of time it will take you to find the item you are looking for if it takes you 5 minutes
to drill into each box.
Input Format
A string that represent the items in each box that will be drilled in order (items are separated by a comma),
and secondly, a string of which item you are looking for.
Output Format
An integer of the amount of time it will take for you to find your item.
Sample Input
'gold,diamonds,documents,Declaration of Independence,keys'
'Declaration of Independence'
Sample Output
20
Explanation
It will take you 20 minutes before you drill into the 4th box, which contains your item, the Declaration of Independence.
*/
depositBoxes = (x,y) => {
var myArray = new Array();
myArray = x;
myArray = myArray.split(",");
console.log(myArray);
var findItem = y;
for(let i = 1; i<=myArray.length; i++){
if(myArray[i] == findItem){
i++;
return console.log(`${y} - Item found within ${i * 5} mins`)
}
}
}
depositBoxes('gold,diamonds,documents,Declaration of Independence,keys', 'Declaration of Independence');
depositBoxes('gold,diamonds,documents,Declaration of Independence,keys', 'keys');
depositBoxes('gold,diamonds,documents,Declaration of Independence,keys', 'gold');
depositBoxes('gold,diamonds,documents,Declaration of Independence,keys', 'diamonds');
/* OUTPUT */
/*
[
'gold',
'diamonds',
'documents',
'Declaration of Independence',
'keys'
]
Declaration of Independence - Item found within 20 mins
[
'gold',
'diamonds',
'documents',
'Declaration of Independence',
'keys'
]
keys - Item found within 25 mins
[
'gold',
'diamonds',
'documents',
'Declaration of Independence',
'keys'
]
diamonds - Item found within 10 mins
*/