Last active
September 19, 2018 13:46
-
-
Save MirzaChilman/e5a9ac1dcf2702b27154f7de2e82c7a3 to your computer and use it in GitHub Desktop.
find the longest sequences letter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
function longestStreak(message){ | |
//case sensitive | |
//make not case sensitive transform to | |
//all upper or lower case | |
let max_char = '' | |
let char = '' | |
let max_count = 0 | |
let count = 0 | |
for(let i = 0 ;i<message.length;i++){ | |
if(i === 0 ){ | |
max_char=message[i] | |
char = message[i] | |
} | |
if(char === message[i]){ | |
count += 1 | |
if(count > max_count){ | |
max_count = count | |
max_char = message[i] | |
} | |
}else { | |
char = message[i] | |
count = 1 | |
} | |
} | |
console.log(max_count) | |
console.log(max_char) | |
} | |
longestStreak('AABDAVCcCBAA') | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function longestStreak(message){ | |
//case sensitive | |
//make not case sensitive transform to | |
//all upper or lower case | |
let max_char = '' | |
let char = '' | |
let max_count = 0 | |
let count = 0 | |
for(let i = 0 ;i<message.length;i++){ | |
if(i === 0 ){ | |
max_char=message[i] | |
char = message[i] | |
} | |
if(char === message[i]){ | |
count += 1 | |
if(count > max_count){ | |
max_count = count | |
max_char = message[i] | |
} | |
}else { | |
char = message[i] | |
count = 1 | |
} | |
} | |
console.log(max_count) | |
console.log(max_char) | |
} | |
longestStreak('AABDAVCcCBAA')</script></body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function longestStreak(message){ | |
//case sensitive | |
//make not case sensitive transform to | |
//all upper or lower case | |
let max_char = '' | |
let char = '' | |
let max_count = 0 | |
let count = 0 | |
for(let i = 0 ;i<message.length;i++){ | |
if(i === 0 ){ | |
max_char=message[i] | |
char = message[i] | |
} | |
if(char === message[i]){ | |
count += 1 | |
if(count > max_count){ | |
max_count = count | |
max_char = message[i] | |
} | |
}else { | |
char = message[i] | |
count = 1 | |
} | |
} | |
console.log(max_count) | |
console.log(max_char) | |
} | |
longestStreak('AABDAVCcCBAA') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment