Skip to content

Commit 61d3e3a

Browse files
committed
Algorithm - findTheLargestElement
1 parent 2f3d8e7 commit 61d3e3a

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,9 @@
3535
1. Hello, what's up? -> Hello
3636
2. I like trains :3 -> trains
3737

38+
7. Find Largest Element
39+
- EXAMPLE
40+
1. 1,3,10,4,6,7,8 -> 10
41+
2. 302,17,35,66,100,1 -> 302
3842

3943

algorithms.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function repeatString()
8585
}
8686

8787
//for loop
88-
for (var index = 1; index <=repeatStringNumber; index++)
88+
for (let index = 1; index <=repeatStringNumber; index++)
8989
{
9090
finalString += repeatStringString;
9191
}
@@ -130,7 +130,7 @@ function findTheLongestString()
130130
var longestWord = '';
131131
var wordArray = noSpecialCharacters.split(' ');
132132

133-
for(var i=0; i<wordArray.length; i++ )
133+
for(let i=0; i<wordArray.length; i++ )
134134
{
135135
if(wordArray[i].length > longestWord.length)
136136
{
@@ -141,4 +141,19 @@ function findTheLongestString()
141141
document.getElementById("findTheLongestStringResult").innerHTML = longestWord;
142142
}
143143

144+
function findTheLargestElement()
145+
{
146+
147+
//EXAMPLE
148+
//1. 1,3,10,4,6,7,8 -> 10
149+
//2. 302,17,35,66,100,1 -> 302
150+
151+
var findTheLargestElementData = document.getElementById("findTheLargestElementInput").value;
152+
var largestElement = null;
153+
var findTheLargestElementSplit = findTheLargestElementData.split(',');
154+
155+
largestElement = Math.max.apply(null,findTheLargestElementSplit);
156+
157+
document.getElementById("findTheLargestElementResult").innerHTML = largestElement;
144158

159+
}

css/main.css

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,8 @@ strong
8686
}
8787

8888
/*-----------------------------------------*/
89-
.contact
90-
{
91-
margin: -.4rem 0 1rem 1.5rem;
92-
}
89+
.contact { margin: -.4rem 0 1rem 1.5rem;}
9390
.contact a { color: #e2e2e2; }
9491
.contact a:hover { color: #fff; }
9592
.contact i { font-size:50px; }
93+
.contact h4 { margin-bottom: 1.5rem;}

index.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,24 @@ <h6> 2. I like trains :3 -> trains </h6>
137137
<p class="lead"> RESULT </p>
138138
<strong id="findTheLongestStringResult"> ------------ </strong>
139139
</div>
140+
141+
<div class="col-4">
142+
<div class="example">
143+
<h1 class="display-4"> Find the Largest Element </h1>
144+
<h3 class="lead"> EXAMPLE </h3>
145+
<h6> 1. 1,3,10,4,6,7,8 -> 10 </h6>
146+
<h6> 2. 302,17,35,66,100,1 -> 302 </h6>
147+
</div>
148+
<div class="row">
149+
<div class="col-8">
150+
<input class="form-control form-control-lg" type="text" id="findTheLargestElementInput" name="findTheLargestElementInput">
151+
</div>
152+
</div>
153+
<button id="btn-space" onclick="findTheLargestElement()" class="btn btn-outline-info btn-lg"> Find the Largest Element! </button>
154+
<p class="lead"> RESULT </p>
155+
<strong id="findTheLargestElementResult"> ------------ </strong>
156+
</div>
157+
140158
</div>
141159

142160

@@ -152,6 +170,7 @@ <h6> 2. I like trains :3 -> trains </h6>
152170

153171
<div class="col-4">
154172
<div class="contact">
173+
<h4>by YunaAnn</h4>
155174
<a target="_blank" rel="noopener noreferrer" href="https://github.com/YunaAnn/JavaScriptAlgorithms"> <i class="fas fa-code"></i></a>
156175
<a target="_blank" rel="noopener noreferrer" href="https://github.com/YunaAnn"><i class="fab fa-github" style="padding-left:10px"></i></a>
157176
</div>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy