Skip to content

Commit d8552a2

Browse files
committed
Algorithm - Find the Smallest Value
1 parent 61d3e3a commit d8552a2

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

README.md

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

38-
7. Find Largest Element
38+
7. Find the Largest Value
3939
- EXAMPLE
4040
1. 1,3,10,4,6,7,8 -> 10
4141
2. 302,17,35,66,100,1 -> 302
4242

43+
8. Find the Smallest Value
44+
- EXAMPLE
45+
1. 1,3,10,4,6,7,8 -> 1
46+
2. 302,17,35,66,100,1 -> 1
47+
4348

algorithms.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,20 @@ function findTheLargestElement()
157157
document.getElementById("findTheLargestElementResult").innerHTML = largestElement;
158158

159159
}
160+
161+
function findTheSmallestElement()
162+
{
163+
164+
//EXAMPLE
165+
//1. 1,3,10,4,6,7,8 -> 1
166+
//2. 302,17,35,66,100,1 -> 1
167+
168+
var findTheSmallestElementData = document.getElementById("findTheSmallestElementInput").value;
169+
var smallestElement = null;
170+
var findTheSmallestElementSplit = findTheSmallestElementData.split(',');
171+
172+
smallestElement = Math.min.apply(null,findTheSmallestElementSplit);
173+
174+
document.getElementById("findTheSmallestElementResult").innerHTML = smallestElement;
175+
176+
}

index.html

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ <h6> 2. I like trains :3 -> trains </h6>
140140

141141
<div class="col-4">
142142
<div class="example">
143-
<h1 class="display-4"> Find the Largest Element </h1>
143+
<h1 class="display-4"> Find the Largest Value </h1>
144144
<h3 class="lead"> EXAMPLE </h3>
145145
<h6> 1. 1,3,10,4,6,7,8 -> 10 </h6>
146146
<h6> 2. 302,17,35,66,100,1 -> 302 </h6>
@@ -150,11 +150,28 @@ <h6> 2. 302,17,35,66,100,1 -> 302 </h6>
150150
<input class="form-control form-control-lg" type="text" id="findTheLargestElementInput" name="findTheLargestElementInput">
151151
</div>
152152
</div>
153-
<button id="btn-space" onclick="findTheLargestElement()" class="btn btn-outline-info btn-lg"> Find the Largest Element! </button>
153+
<button id="btn-space" onclick="findTheLargestElement()" class="btn btn-outline-info btn-lg"> Find the Largest Value! </button>
154154
<p class="lead"> RESULT </p>
155155
<strong id="findTheLargestElementResult"> ------------ </strong>
156156
</div>
157157

158+
<div class="col-4">
159+
<div class="example">
160+
<h1 class="display-4"> Find the Smallest Value </h1>
161+
<h3 class="lead"> EXAMPLE </h3>
162+
<h6> 1. 1,3,10,4,6,7,8 -> 1 </h6>
163+
<h6> 2. 302,17,35,66,100,1 -> 1 </h6>
164+
</div>
165+
<div class="row">
166+
<div class="col-8">
167+
<input class="form-control form-control-lg" type="text" id="findTheSmallestElementInput" name="findTheSmallestElementInput">
168+
</div>
169+
</div>
170+
<button id="btn-space" onclick="findTheSmallestElement()" class="btn btn-outline-info btn-lg"> Find the Smallest Value! </button>
171+
<p class="lead"> RESULT </p>
172+
<strong id="findTheSmallestElementResult"> ------------ </strong>
173+
</div>
174+
158175
</div>
159176

160177

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