Content-Length: 405056 | pFad | http://github.com/YunaAnn/JavaScriptAlgorithms/commit/2f3d8e7195b4e19576dd9bd590a7503173299abc

35 Algorithms - Find the Longest String · YunaAnn/JavaScriptAlgorithms@2f3d8e7 · GitHub
Skip to content

Commit 2f3d8e7

Browse files
committed
Algorithms - Find the Longest String
1 parent fe09d3a commit 2f3d8e7

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,10 @@
3030
1. cat, 5 -> catcatcatcatcat
3131
2. rain, 4' -> rainrainrainrain
3232

33+
6. Find the Longest String
34+
- EXAMPLE
35+
1. Hello, what's up? -> Hello
36+
2. I like trains :3 -> trains
37+
3338

3439

algorithms.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function reverseString()
5151
var reverseString = document.getElementById("reverseString").value;
5252

5353
var reverseStringResult = reverseString.split('').reverse().join('');
54-
54+
5555
//option 2:
5656
//var reverseStringResult = [...reverseString].reverse().join('');
5757

@@ -117,4 +117,28 @@ function alphabetizeString()
117117
document.getElementById("alphabetizeStringResult").innerHTML = alphabetizeStrResult;
118118
}
119119

120+
function findTheLongestString()
121+
{
122+
123+
//EXAMPLE
124+
//Hello, what's up? -> Hello
125+
//I like trains :3 -> trains
126+
127+
var findTheLongestStringStr = document.getElementById("findTheLongestStringInput").value;
128+
129+
var noSpecialCharacters = findTheLongestStringStr.replace(/\W/g,' ');
130+
var longestWord = '';
131+
var wordArray = noSpecialCharacters.split(' ');
132+
133+
for(var i=0; i<wordArray.length; i++ )
134+
{
135+
if(wordArray[i].length > longestWord.length)
136+
{
137+
longestWord = wordArray[i];
138+
}
139+
}
140+
141+
document.getElementById("findTheLongestStringResult").innerHTML = longestWord;
142+
}
143+
120144

index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,27 @@ <h6> Do geese see God? </h6>
119119
<strong id="palindromeResult"> ------------ </strong>
120120
</div>
121121
</div>
122+
123+
<div class="row">
124+
<div class="col-4">
125+
<div class="example">
126+
<h1 class="display-4"> Find the Longest String </h1>
127+
<h3 class="lead"> EXAMPLE </h3>
128+
<h6> 1. Hello, what's up? -> Hello </h6>
129+
<h6> 2. I like trains :3 -> trains </h6>
130+
</div>
131+
<div class="row">
132+
<div class="col-8">
133+
<input class="form-control form-control-lg" type="text" id="findTheLongestStringInput" name="findTheLongestStringInput">
134+
</div>
135+
</div>
136+
<button id="btn-space" onclick="findTheLongestString()" class="btn btn-outline-info btn-lg"> Find the Longest String! </button>
137+
<p class="lead"> RESULT </p>
138+
<strong id="findTheLongestStringResult"> ------------ </strong>
139+
</div>
140+
</div>
141+
142+
122143
</div>
123144
</div>
124145
</div>

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/YunaAnn/JavaScriptAlgorithms/commit/2f3d8e7195b4e19576dd9bd590a7503173299abc

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy