Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private.search = function (values) {
- var
- max = 0,
- row = [],
- pizza = [];
- if (values) {
- for (var place in private.PLACES) {
- var
- p = [],
- l = private.PLACES[place].pizza.length;
- for (var i = l; i--; ) {
- var
- contain = 0,
- user_components = values,
- maximum = user_components.length,
- pizza_components = private.PLACES[place].pizza[i].components.split(','),
- j = pizza_components.length;
- while (j--) {
- if (user_components.indexOf(pizza_components[j]) > -1) {
- contain += 1;
- } else {
- maximum += 1;
- }
- }
- var
- o = {
- name: private.PLACES[place].pizza[i].name,
- price: private.PLACES[place].pizza[i].price,
- percent: parseFloat((contain / maximum * 100).toFixed(2)),
- components: pizza_components
- }
- p.push(o);
- }
- max = private.getMax(private.getArrayOfArrayObjs(p, 'percent'));
- var myArray = p.filter(function(o) {
- return o.percent === max;
- });
- pizza.push({
- arr: myArray,
- address: private.PLACES[place].address,
- name: place
- });
- }
- private.results.empty().show();
- $('<thead>').append(
- $('<tr>').append(
- $('<td>', { text: 'Zgdność' }),
- $('<td>', { text: 'Pizza' }),
- $('<td>', { text: 'Cena' }),
- $('<td>', { text: 'Pizzeria' }),
- $('<td>', { text: 'Adres' }),
- $('<td>', { text: 'Składniki' })
- )
- ).appendTo('#results');
- $('<tbody>').appendTo('#results');
- $.each(pizza, function (index, value) {
- var
- placeName = value.name,
- placeAddress = value.address;
- $.each(value.arr, function (index, value) {
- row.push($('<tr>').append(
- $('<td>', { text: value .percent, class: 'percent' }),
- $('<td>', { text: value .name}),
- $('<td>', { text: value .price + 'zł'}),
- $('<td>', { text: placeName }),
- $('<td>', { text: placeAddress }),
- $('<td>', { text: private.getNames(value.components).join(', ') })
- ));
- });
- });
- row = row.sort(function (a, b) {
- return parseInt(a.find('.percent').text(), 10) < parseInt(b.find('.percent').text(), 10);
- });
- $.each(row, function (index, value) {
- value.appendTo('#results > tbody');
- });
- } else {
- private.results.hide();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement