Last active
February 21, 2021 12:33
-
-
Save ablamohamedamine/e198b1970869af82e716f759fddb1f28 to your computer and use it in GitHub Desktop.
tri-algorithme
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 lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link rel="stylesheet" href="style.css"> | |
<title>Tri</title> | |
</head> | |
<body> | |
<section> | |
<div id="block"> | |
<form id="form"> | |
<input type="number"> | |
</form> | |
<p id="result">Result: </p> | |
</div> | |
<div id="buttons"> | |
<button onclick="addInput()">Add</button> | |
<button onclick="showResluts()">Result</button> | |
</div> | |
</section> | |
<script src="main.js"></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
var inputs = document.getElementsByTagName('input'), | |
excludes = [], | |
i = 0; | |
function ifNotExist(elemet, array) { | |
for(value of array) { | |
if (elemet === value) return false | |
} | |
return true | |
} | |
function tri(array) { | |
let max = 0; | |
for(element of array) { | |
if(element > max && ifNotExist(element, excludes)) max = element | |
} | |
excludes[i] = max; | |
i++; | |
} | |
function addInput() { | |
input = document.createElement('input') | |
document.getElementById("form").appendChild(input) | |
input.setAttribute("type", "number") | |
} | |
function showResluts() { | |
var result = document.getElementById('result'), | |
results = [], | |
numbers = [], | |
spans = document.getElementsByTagName('span'); | |
excludes = []; | |
i = 0; | |
while(spans[0]) spans[0].parentNode.removeChild(spans[0]); | |
for (let l = 0; l < inputs.length; l++) { | |
numbers[l] = inputs[l].value; | |
} | |
for (j = 0; j < numbers.length; j++) { | |
tri(numbers); | |
} | |
for (k = 0; k < excludes.length; k++) { | |
results[k] = document.createElement('span') | |
results[k].innerText = excludes[k] | |
result.appendChild(results[k]) | |
} | |
} |
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
* { | |
box-sizing: border-box; | |
padding: 0; | |
margin: 0; | |
font-family: 'Tahoma'; | |
} | |
section { | |
width: 20%; | |
margin: auto; | |
} | |
#block, | |
#form, | |
#buttons { | |
display: flex; | |
flex-direction: column; | |
} | |
#block, | |
#buttons { | |
padding: 1rem; | |
} | |
input, button{ | |
font-family: 'Tahoma'; | |
width: 100%; | |
padding: 5px; | |
margin-bottom: 10px; | |
border-radius: 2px; | |
-webkit-border-radius: 2px; | |
-moz-border-radius: 2px; | |
-ms-border-radius: 2px; | |
-o-border-radius: 2px; | |
border: 3px solid rgb(41, 11, 11); | |
outline: none |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment