JSFiddle - React, Tailwind, and code Playground
by mmarcon
HTML
<form>
<textarea id="input" cols="40" rows="30" name="input">
free-lunch 802
mixed-nuts 421
orange-juice 143
heavy-ddr-session -302
cheese-snacks 137
cookies 316
mexican-coke 150
dropballers-basketball -611
coding-six-hours -466
riding-scooter -42
rock-band -195
playing-drums -295
</textarea>
</form>
CSS
body {
background: #E4E4DB;
}
#input {
font-family: helvetica;
font-size: 14px;
font-weight: 100;
width: 400px;
height: 300px;
border: 0;
margin: 10px auto;
display: block;
border-radius: 4px;
padding: 10px;
box-shadow: 0 0 10px #ccc;
}
JavaScript
var Diet = function() {
var settings = {
input: $('#input')
},
food = [],
activities = [],
foodMask = 0,
activityMask = 0;
var readInput = function() {
var text = settings.input.val(),
lines = text.split('\n'),
i, l, sortFn;
for (i = 0; i < lines.length; i++) {
if (lines[i].length === 0) {
continue;
}
l = lines[i].trim().split(' ');
if (l[1] > 0) {
food.push({
name: l[0],
calories: l[1]
});
}
else {
activities.push({
name: l[0],
calories: -1 * l[1]
});
}
}
sortFn = function (a, b) {
return a.calories - b.calories;
};
food.sort(sortFn);
activities.sort(sortFn);
console.log(food);
console.log(activities);
};
var think = function() {
var i, j;
for (i = 0; i < Math.pow (2, food.length); i++) {
}
};
var getSum = function (array, mask) {
console.log (mask);
var sum = 0, i;
for (i = 0; i < array.length; i++) {
if (i >= mask.length) break;
sum += parseInt (mask.charAt(i));
}
};
this.init = function() {
readInput();
think();
};
};
$(function() {
new Diet().init();
});