Created
August 7, 2013 22:11
-
-
Save danielef/6179287 to your computer and use it in GitHub Desktop.
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
textarea { | |
padding: 5px; | |
width: 90%; | |
height: 200px; | |
} | |
div { | |
padding: 5px; | |
width: 100%; | |
} | |
button { | |
width: 90%; | |
} |
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
<html> | |
<head> | |
<title>Problema 2</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script> | |
<script src="http://documentcloud.github.io/underscore/underscore-min.js"></script> | |
</head> | |
<body> | |
<div> | |
<textarea id="n">hugo paco luis</textarea> | |
</div> | |
<div> | |
<button id="e">evaluar nombres separados por espacios</button> | |
</div> | |
<div> | |
<textarea id="a"></textarea> | |
</div> | |
</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
$(document).ready(function() { | |
$("#e").click(function() { | |
$("#a").val(""); | |
_.map(roundRobin($("#n").val().split(" ")), function (p) { | |
$("#a").val($("#a").val()+p+"\n"); | |
}); | |
}); | |
}); | |
function roundRobin(a) { | |
return (a.length < 2)? | |
combine(_.first(a),_.rest(a)): | |
combine(_.first(a),_.rest(a)).concat(roundRobin(_.rest(a))); | |
} | |
function combine(target, a) { | |
return _.map(a, function(n) { return [target, n]; }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment