Creo String to Integer Relation
<html> | |
<head> | |
<script type='text/javascript' src='http://cdnjs.cloudflare.com/ajax/libs/knockout/3.1.0/knockout-min.js'></script> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<script> | |
$(function() { | |
var ViewModel = function() { | |
this.stringLength = ko.observable(5); | |
this.inputName = ko.observable("input"); | |
this.outputName = ko.observable("output"); | |
this.relation = ko.computed(function() { | |
var output = ""; | |
for (i = 1; i <= this.stringLength(); i++) { | |
output += this.outputName() + "_C" + i + "=extract("+this.inputName()+"," + i + ",1)\n"; | |
} | |
output += this.outputName() + " = 0\n"; | |
for (level = 0; level < this.stringLength(); level++) { | |
for (i = 1; i < 10; i++) { | |
output += "if("+this.outputName()+"_C" + (level+1)+"==\"" + i +"\")\n"; | |
output += this.outputName()+"="+this.outputName()+"+" + i * Math.pow(10, this.stringLength()-level-1) + "\n"; | |
output += "endif\n"; | |
} | |
} | |
return output; | |
}, this); | |
}; | |
ko.applyBindings(new ViewModel()); | |
}); | |
</script> | |
</head> | |
<body> | |
<p>String Length: <input data-bind="value: stringLength, valueUpdate:'afterkeydown'" /></p> | |
<p>String Param: <input data-bind="value: inputName, valueUpdate:'afterkeydown'" /></p> | |
<p>Output Param: <input data-bind="value: outputName, valueUpdate:'afterkeydown'" /></p> | |
<hr /> | |
<p>Relation: </p> | |
<textarea data-bind="text: relation" rows="50" cols="100"> </textarea> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment