forked from AdamMomen/warmUp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwarmUp16.js
More file actions
54 lines (36 loc) · 1.19 KB
/
Copy pathwarmUp16.js
File metadata and controls
54 lines (36 loc) · 1.19 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
// Given a string text, you want to use the characters of text to form as many instances of the word "balloon"
//as possible.
// You can use each character in text at most once. Return the maximum number of instances that can be formed.
// Example 1:
// Input: text = "nlaebolko"
// Output: 1
// Example 2:
// Input: text = "loonbalxballpoon"
// Output: 2
// Example 3:
// Input: text = "RebootKamp"
// Output: 0
// Constraints:
// 1 <= text.length <= 10^4
// text consists of lower case English letters only.
function chop(str){
var arr = str.split('');
var arr2;
var acc = 0;
if (str.length < 6) {
return acc
}
if (arr.indexOf("b") !== -1 &&arr.indexOf("a")!== -1 &&arr.indexOf("l")!== -1 &&arr.indexOf("o")!== -1 &&arr.indexOf("n")!== -1){
arr2 = arr.splice(arr.indexOf("l"),1);
arr2 = arr.splice(arr.indexOf("o"),1);
if (arr.indexOf("b")&&arr.indexOf("a")&&arr.indexOf("l")&&arr.indexOf("o")&&arr.indexOf("n")){
arr2 = arr.splice(arr.indexOf("b"),1);
arr2 = arr.splice(arr.indexOf("a"),1);
arr2 = arr.splice(arr.indexOf("l"),1);
arr2 = arr.splice(arr.indexOf("o"),1);
arr2 = arr.splice(arr.indexOf("n"),1);
acc = acc + 1;
}
}
return chop (arr2.join(''));
}