Skip to content

Instantly share code, notes, and snippets.

@danielef
Created August 7, 2013 22:11
Show Gist options
  • Save danielef/6179287 to your computer and use it in GitHub Desktop.
Save danielef/6179287 to your computer and use it in GitHub Desktop.
textarea {
padding: 5px;
width: 90%;
height: 200px;
}
div {
padding: 5px;
width: 100%;
}
button {
width: 90%;
}
<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>
$(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