-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchallenge1.js
More file actions
52 lines (43 loc) · 1.55 KB
/
challenge1.js
File metadata and controls
52 lines (43 loc) · 1.55 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
//Using the JavaScript language, have the function NumberStream(str) take the str parameter being passed which will contain the numbers 2 through 9, and determine if
//there is a consecutive stream of digits of at least N length where N is the actual digit value. If so, return the string true, otherwise return the string false. For
//example: if str is "6539923335" then your program should return the string true because there is a consecutive stream of 3's of length 3. The input string will always
//contain at least one digit.
// Sample Test Cases
// Input:"5556293383563665"
// Output:"false"
// Input:"5788888888882339999"
// Output:"true"
const NumberStream = str => {
let currentMatchingDigit = null;
let currentCountOfDigit = 1;
for (let i = 1; i <= str.length; i++) {
if (str[i] === str[i - 1]) {
currentMatchingDigit = str[i];
currentCountOfDigit += 1;
} else {
currentMatchingDigit = null;
currentCountOfDigit = 1;
}
if (parseInt(currentCountOfDigit) === parseInt(currentMatchingDigit)) {
return true;
}
}
return false;
};
console.log(NumberStream('5556293383563665'), false);
console.log(NumberStream('5788888888882339999'), true);
console.log(NumberStream('6539923335'), true);
console.log(NumberStream('653992335'), false);
console.log(NumberStream('65399233335'), true);
console.log(NumberStream('653992333'), true);
console.log(NumberStream('22'), true);
//Object Deconstruction
const obj = {
foo: 'bar',
baz: 'bam',
color: 'blue',
};
const whatColor = ({ color: favorite }) => {
return 'My Color ' + favorite;
};
whatColor(obj);