โŒ

Normal view

There are new articles available, click to refresh the page.
Before yesterdayMain stream

Sorting user-defined array with strings gives wrong order, even when file content is fully available on disk

I am querying ElasticSearch and sorting the documents locally in Bash with jq, as sorting in ES is too slow for me.

The original purpose is to create a CSV file.

But I find the sorting does not work properly, it seems sort step does nothing.

As I am launching cURL requests, I thought the wrong order is due to content is chunked so I save some results into a local test.json file and tried again, but it still does not work.

test.json:

{
    "took": 680,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "max_score": 1.0,
        "hits": [
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111113584925",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111113584925"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111121254059",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111121254059"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111116879444",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111116879444"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111116879484",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111116879484"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111114472530",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111114472530"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111113372966",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111113372966"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111113046053",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111113046053"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111113034864",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111113034864"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111116770197",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111116770197"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111123578950",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111123578950"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111114472544",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111114472544"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111123578971",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111123578971"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111124882870",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111124882870"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111124178732",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111124178732"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111113649568",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111113649568"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111113034877",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111113034877"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111114049560",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111114049560"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111113034894",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111113034894"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111116879498",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111116879498"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111115634604",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111115634604"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111117550495",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111117550495"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111117964387",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111117964387"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111120647956",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111120647956"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111124178784",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111124178784"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111123579003",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111123579003"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111114049597",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111114049597"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111113922927",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111113922927"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111113649622",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111113649622"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111113922948",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111113922948"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111124178797",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111124178797"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111114775147",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111114775147"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111115634973",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111115634973"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111115634987",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111115634987"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111124882959",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111124882959"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111114049664",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111114049664"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111117964419",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111117964419"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111117069687",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111117069687"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111117453564",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111117453564"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111113046124",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111113046124"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111113586875",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111113586875"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111115735339",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111115735339"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111119990227",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111119990227"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111120648051",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111120648051"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111117453835",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111117453835"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111113899778",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111113899778"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111120648071",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111120648071"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111117964461",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111117964461"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111114049666",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111114049666"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111114049678",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111114049678"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111113923053",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111113923053"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111119990248",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111119990248"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111115735378",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111115735378"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111115735384",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111115735384"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111116770587",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111116770587"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111124883047",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111124883047"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111114775219",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111114775219"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111113373129",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111113373129"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111113046216",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111113046216"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111124883526",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111124883526"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111113046278",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111113046278"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111113587608",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111113587608"
                    ]
                }
            },
            {
                "_index": "my-index",
                "_type": "_doc",
                "_id": "111111116770696",
                "_score": 1.0,
                "fields": {
                    "field2": [
                        "FOO"
                    ],
                    "field1": [
                        "111111116770696"
                    ]
                }
            }
        ]
    }
}

Command that I use:

jq '.hits.hits[].fields | [.field1[0] + "," + .field2[0]] | sort | .[0]' -r test.json

The result:

111111113584925,FOO
111111121254059,FOO
111111116879444,FOO
111111116879484,FOO
111111114472530,FOO
111111113372966,FOO
111111113046053,FOO
111111113034864,FOO
111111116770197,FOO
111111123578950,FOO
111111114472544,FOO
111111123578971,FOO
111111124882870,FOO
111111124178732,FOO
111111113649568,FOO
111111113034877,FOO
111111114049560,FOO
111111113034894,FOO
111111116879498,FOO
111111115634604,FOO
111111117550495,FOO
111111117964387,FOO
111111120647956,FOO
111111124178784,FOO
111111123579003,FOO
111111114049597,FOO
111111113922927,FOO
111111113649622,FOO
111111113922948,FOO
111111124178797,FOO
111111114775147,FOO
111111115634973,FOO
111111115634987,FOO
111111124882959,FOO
111111114049664,FOO
111111117964419,FOO
111111117069687,FOO
111111117453564,FOO
111111113046124,FOO
111111113586875,FOO
111111115735339,FOO
111111119990227,FOO
111111120648051,FOO
111111117453835,FOO
111111113899778,FOO
111111120648071,FOO
111111117964461,FOO
111111114049666,FOO
111111114049678,FOO
111111113923053,FOO
111111119990248,FOO
111111115735378,FOO
111111115735384,FOO
111111116770587,FOO
111111124883047,FOO
111111114775219,FOO
111111113373129,FOO
111111113046216,FOO
111111124883526,FOO
111111113046278,FOO
111111113587608,FOO
111111116770696,FOO

Why?

Should I rely on jq sorting? Am I using it correctly? I mean I want to do string comparison by alphabetical order, and field1 all have unique values, so it will never be a tie and start to compare values of field2(it also could have various values but I only want to sort by field1)

Should I use Bash sort -k 1 instead? Which is faster when it comes to 100K rows?

Sort List in Alphanumeric Order

Editing for more context:

I'm trying to sort a list after zip.

list_sort= zip(l1, l2)

l1 = ['F2', 'G2', 'A10', 'H2', 'A3', 'E3', 'B10', 'C1', 'D1', 'E1', 'D2', 'C11', 'A1']
l2 = [40, 40, 90, 90, 90, 90, 90, 120, 120, 120, 120, 120, 90]

I'm looking to sort l1 in this order:

l1 = ['A1', 'C1', 'D1', 'E1', 'D2', 'F2', 'G2', 'H2', 'A3', 'E3', 'A10', 'B10', 'C11']

l2 will sort with l1

l2 = [90, 120, 120, 120, 120, 40, 40, 90, 90, 90, 90, 90, 120]

What I have tried:

list(sorted(list_sort, key=lambda item: (item[0][1], item[0][1:0])))

Combining relevant data in two different arrays

Can you help on how to combine data in two different arrays with different structures?

I take data via API, the first request:

[
  {
    "category_id": "12345",
    "category_name": "itemgroup 1",
    "category_is_hidden": "0",
    "product_id": "9999999",
    "product_name": "item 1",
    "product_sku": "0002344",
    "product_brand": null,
    "product_vendor_code": "art 123",
    "is_productset": "0",
    "productset_items": null,
    "is_service": "0",
    "is_serial": "0",
    "variations": {
      "id": "1122334455",
      "name": "red",
      "measurement_unit": "unit_piece",
      "quantity_minimal_piece": "1.000",
      "sku": null,
      "vendor_code": "",
      "retail_price": "2550.00",
      "wholesale_price": "2550.00",
      "discount_type": "percent",
      "discount": "0.00",
      "barcodes": ["2000471000002", "2000481000009"]
    }
  }
]

second request:

[
  {
    "9999999": {
      "company_id": 63,
      "branch_id": 69,
      "variation_id": 954629,
      "supplier_id": 0,
      "quantity": 1
    }
  }
]

I need to match the data by product_id and get the output in the format: Product Name, Quantity

At the moment I only came up with:

async function getstockandproductinfo() {
  try {
    const stockinforesponse = await axios.get(`${BASE_URL}/stock?branch_id=0`, {
      headers: {'API-KEY': API_KEY}
    });
    const productinforesponse = await axios.get (`${BASE_URL}/products`, {
      headers: {'API-KEY': API_KEY}
    });
    const productdata = productinforesponse.data;
    const stocksdata = stockinforesponse.data;
    const meld = [].concat(productdata, stocksdata);

    meld.forEach(item => {
      if (typeof item === 'object' && item !== null) {
        for (const product_id in item) {
          if (item[product_id] && item[product_id].hasOwnProperty('quantity')) {
            const quantity = item[product_id].quantity;
            console.log(`Product ID: ${product_id}, Quantity: ${quantity}`);
          }
        }
      }
    });

  } catch (error) {
    console.error('Error', error);
  }
}

getstockandproductinfo();

when I try to get the product name I get undefined

I will be glad for any help, as I am a complete noob)

How can I alphabetically sort second dimension of an array [duplicate]

Iยดm trying to sort the last dimension of the following array

$inventory = array(
    "author" => array(
        "1" => "Evans, Dave",
        "2" => "Burnett, Bill",
    ),
    "title" => array(
        "1" => "Designing your life",
    ),
    "subject" => array(
        "1" => "Vocational guidance",
        "2" => "Decision making",
        "3" => "Self-realization",
    )
);

The desired output would be something like this:

authorโ€ƒ Burnett, Bill
authorโ€ƒ Evans, Dave
titleโ€ƒ  Designing your life
subjectโ€ƒDecision making
subjectโ€ƒSelf-realization
subjectโ€ƒVocational guidance

There are a bunch of sorting examples that doesn't work. Any ideas? Please don't answer without testing.

Sort subarray values of a 2d array and preserve first level keys

I find other thread about sort multidimensional array, but it's not the same problem.

$arr[22][] = 45;
$arr[22][] = 44;
$arr[22][] = 99;

$arr[23][] = 95;
$arr[23][] = 55;
$arr[23][] = 1;

echo "<pre>";
print_r($arr);
echo "</pre>";

I want to sort the value inside subarray, not the value between sub array.

The expected result is

[22] => Array [0 ] => 44 [1] => 45 [2] => 99

[23] => Array [0 ] => 1 [1] => 55 [2] => 95

I try with

array_multisort($arr[22], SORT_ASC, SORT_NUMERIC
                , $arr[23], SORT_ASC, SORT_NUMERIC);

but it's not correct anyway.

How could I do?

Number Pattern Anomaly Detection in Python

I am trying to find the anomalous pattern in Order Confirmation Numbers.

For example ABC client has this below pattern:

390142567
395142611
4001x
400
400142614
497142759
500142813
230123315

Here is increasing changing pattern of client and below are anomalies

4001x
400
230123315

which are not following pattern

How to detect these anomalies?

Symfony 6 order entity by relation entity property

I am pretty new on Symfony and i didn't find or understand how to manage my issue.

I am using Symfony 6, php 8 and knppaginator to display a CRUD.

I have a Country entity which have an id and a name

class Country {
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private int $id;

    #[ORM\Column(length: 255)]
    #[Assert\NotBlank()]
    private string $name;

    #[ORM\OneToMany(mappedBy: 'country', targetEntity: Shop::class, orphanRemoval: true)]
    #[ORM\OrderBy(['name' => 'ASC'])]
    private Collection $shops;

and a Shop entity which have an id, name and a relation manyToOne with the Country entity

class Shop{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private int $id;

    #[ORM\ManyToOne(inversedBy: 'shops')]
    #[ORM\JoinColumn(nullable: false)]
    private Country $country;

    #[ORM\Column(length: 255)]
    #[Assert\NotBlank()]
    private string $name;

On my Shop index page i display a simple table id|shop name|country name.

I am able to sort on these fields with kpnpaginator but the country field is sorted by id.

    public function index(ShopRepository $shopRepository, PaginatorInterface $paginator, Request $request): Response
{
    $shops = $paginator->paginate(
        $shopRepository->findAll(),
        $request->query->getInt('page', 1),
        10
    );

    return $this->render('index.html.twig', [
        'shops' => $shops ,
    ]);
}

How can i sort this field by country name ?

Most efficient way to get the largest 3 elements of an array using no comparisons but a procedure for ordering 5 elements descendantly

I have been given an array of elements and a function which can sort 5 elements at a time.
How do I use only this function to obtain the largest 3 elements of the array with the least number of calls to this function?

The approach I have tried is dividing the array in groups of 5 each, applying the function on each group, and applying the function on the maximums obtained from each group.

This approach fails when the highest and second highest happen to be present in the same group.
Is there a better approach to do this?

Hoare Partition Algorithm Index out of a bounds

some page 178 depicting an ALGORITHM HoarePartition

while array[i] <= pivot:
    i += 1
    # print("I")
    if i == len(array):
        i -= 1
        break

This is what I am using to prevent the out of a bounds problem, but I think I am not implementing the idea of a "sentinel" as it appears in the text and my algorithm is running much slower than I anticipated.

What does the book mean when it says append a "sentinel" to the array A[0..n-1]?

Office-js Excel Sort Worksheet range by multiple criteria

Trying to sort a range of values in excel online using the office.js javascript api by multiple criteria but getting very inconsistent results. I'm attempting to sort based on the value ascending in column 1 but also by font color so each font color is ordered by the value of column 1 in ascending order.

results are very inconsistent. Is there a better way to do this?

async function sort(worksheetName) {
    await Excel.run(async (context) => {
      worksheet = context.workbook.worksheets.getItem(worksheetName);
      console.log("sort worksheet:" + worksheetName);
      let myUsedRange = worksheet.getUsedRange();
      let lastrow = myUsedRange.getLastRow().load(["rowindex", "values"]);
      await context.sync();
      let lastrowindex = lastrow.rowIndex + 1;

      // Add values to the range
      let range = worksheet.getRange("A5:M" + lastrowindex);
      console.log("lastrow index sort:" + lastrowindex);
      // Sort the range
      const sortFields = [
        {
          key: 1,
          sortOn: Excel.SortOn.fontColor,
          ascending: true
        },
        {
          key: 1,
          sortOn: Excel.SortOn.value,
          ascending: true
        },       
      ];
      
      range.sort.apply(sortFields);

      await context.sync();
    });
  }
โŒ
โŒ