table expand, table expand ignore case
These functions work very similarly like table integrate(). Instead of stopping at the first match in the lookup table, this function family looks up all entries in the lookup table. The search procedure through the lookup table will always be top-down. If only one match has been identified, then the behavior is the same as in table integrate(). In case 2 or more matching enties are found in the lookup table, then the following happens:
Additional features:
Indirect parameter passing is disabled
6 - 9 (For parameter description and return values: see table integrate() )
table initialize( nute facts, // Nutritional facts, source: ndb.nal.usda.gov
{ { Food, Ingredient, Portion },
{ potato chips, fat, 0.34 },
{ potato chips, carbohydrates, 0.50 },
{ potato chips, sodium, 0.08 },
{ potato chips, proteins, 0.07 },
{ potato chips, others, '' }, // Remaining weight subtracted from above (--> operation identifer 'mul')
{ broccoli, water, 0.90 },
{ broccoli, proteins, 0.03 },
{ broccoli, carbohydrates, 0.06 },
{ broccoli, others, '' }, // Remaining weight subtracted from above (--> operation identifer 'mul')
{ spring water, water, 1.00 } } );
table initialize( target, { { Name, Favorite Food, Weight },
{ Rafael, Broccoli, 200 }, { Steve, Parmesan cheese, 100 }, { Stephanie, Parmesan cheese, 200 },
{ Jane, Potato chips,100 }, { Nick, Potato chips, 50 }, { Fred, Spring water, 1000 } } );
echo("Target table before looking up with expanding contents:");
table list ( target );
count[] = table expand ignore case( target, Favorite Food, { Ingredient, Weight }, nute facts, Food,
{ Ingredient, Portion }, { overwrite, mul}, true, Counter );
echo("Lookup table:");
table list ( nute facts );
// Note that food portions are multiplied with the weight of the food.
echo("After expanding (listing ingredients and calculating their weights):");
echo("Note: Nothing found for parmesan cheese.");
echo("Target table after lookup (", count[], " items found):");
table list ( target );
Target table before looking up with expanding contents:
0 : Name | Favorite Food | Weight
1 : Rafael | Broccoli | 200
2 : Steve | Parmesan cheese | 100
3 : Stephanie | Parmesan cheese | 200
4 : Jane | Potato chips | 100
5 : Nick | Potato chips | 50
6 : Fred | Spring water | 1000
Lookup table:
0 : Food | Ingredient | Portion | Counter
1 : potato chips | fat | 0.34 | 2
2 : potato chips | carbohydrates | 0.50 | 2
3 : potato chips | sodium | 0.08 | 2
4 : potato chips | proteins | 0.07 | 2
5 : potato chips | others | | 2
6 : broccoli | water | 0.90 | 1
7 : broccoli | proteins | 0.03 | 1
8 : broccoli | carbohydrates | 0.06 | 1
9 : broccoli | others | | 1
10 : spring water | water | 1.00 | 1
After expanding (listing ingredients and calculating their weights):
Note: Nothing found for parmesan cheese.
Target table after lookup (15 items found):
0 : Name | Favorite Food | Weight | Ingredient
1 : Rafael | Broccoli | 180 | water
2 : Rafael | Broccoli | 6 | proteins
3 : Rafael | Broccoli | 12 | carbohydrates
4 : Rafael | Broccoli | 2 | others
5 : Steve | Parmesan cheese | 100 |
6 : Stephanie | Parmesan cheese | 200 |
7 : Jane | Potato chips | 34 | fat
8 : Jane | Potato chips | 50 | carbohydrates
9 : Jane | Potato chips | 8 | sodium
10 : Jane | Potato chips | 7 | proteins
11 : Jane | Potato chips | 1 | others
12 : Nick | Potato chips | 17 | fat
13 : Nick | Potato chips | 25 | carbohydrates
14 : Nick | Potato chips | 4 | sodium
15 : Nick | Potato chips | 3.5 | proteins
16 : Nick | Potato chips | 0.5 | others
17 : Fred | Spring water | 1000 | water
table expand fast
table expand smart
table expand with rules
table expand with rules once
table lookup
table integrate
table digest