Created
April 22, 2012 19:03
-
-
Save Schabernack/2466195 to your computer and use it in GitHub Desktop.
Mengenaddierer
This file contains 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 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | |
"http://www.w3.org/TR/html4/loose.dtd"> | |
<html> | |
<head> | |
<title>Uhr</title> | |
</head> | |
<script type="text/javascript"> | |
function Set(valuestring){ | |
this.mengenwerte = new Array(); | |
this.addValues(valuestring); | |
} | |
// String am Komma auftrennen und in Array schreiben. | |
// Werte in Map schreiben um duplikate zu entfernen. key == value == zahl | |
Set.prototype.addValues = function(valuestring){ | |
if(valuestring){ | |
valuearray = valuestring.split(','); | |
for(i=0; i<valuearray.length; i++){ | |
this.mengenwerte[valuearray[i]] = valuearray[i]; | |
} | |
} | |
} | |
// mengen schneiden. doppelte werte werden überschrieben. | |
Set.prototype.getUnion = function(anotherSet){ | |
for(i=0; i<anotherSet.mengenwerte.length;i++){ | |
this.mengenwerte[anotherSet.mengenwerte[i]] = anotherSet.mengenwerte[i]; | |
} | |
var returnvalue=""; | |
for(i=0; i<this.mengenwerte.length;i++){ | |
if(this.mengenwerte[i]){ | |
returnvalue+=this.mengenwerte[i]; | |
if(i!=this.mengenwerte.length-1 ){ | |
returnvalue+=","; | |
} | |
} | |
} | |
return returnvalue; | |
} | |
function addiereSets(){ | |
values1 = new Set(document.getElementById('feld1').value); | |
values2 = new Set(document.getElementById('feld2').value); | |
document.getElementById('result').value=values1.getUnion(values2); | |
} | |
</script> | |
<body> | |
<div id="uhr"/> | |
<input id="feld1" value="1,2,3" type="text"/> | |
<input id="feld2" value="2,3,4"type="text"/> | |
<input type="button" value="=" onclick="addiereSets()"/> | |
<input id="result"> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment