Skip to content

Instantly share code, notes, and snippets.

@leopic
Created March 30, 2014 08:03
Show Gist options
  • Save leopic/9869271 to your computer and use it in GitHub Desktop.
Save leopic/9869271 to your computer and use it in GitHub Desktop.
// TODO: filtro?
crear y destruir los ingredientes
var ingredientes = '2@Tazas de arroz; 3@Aguacates mexicanos; 1@Banano en rodajas;',
separadorIngredientes = ';',
separadorCantidades = '@';
var separados = _.map(_.compact(ingredientes.split(separadorIngredientes)), function(ingArr) {
var tmp = ingArr.trim().split(separadorCantidades);
return {
cantidad: parseInt(_.first(tmp), 10),
nombre: _.last(tmp)
};
});
var juntos = _.reduce(separados, function(prev, ingObj) {
return _.toArray(ingObj).join(separadorCantidades) + separadorIngredientes + prev;
}, '');
@leopic
Copy link
Author

leopic commented Apr 1, 2014

serivicio!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment