dimanche 20 septembre 2020

How to write an efficient algorithm to prioritise order?

I have to prioritise orders and have the following flow diagram enter image description here

This is an amateur solution, I could make it better, what I would like to learn is how to write fast and efficient code. If you could guide me and provide what algorithm or pattern I should investigate that would be great, thanks.

priority = int
productType2 = []    

if deliveryCountry = uk

    foreach(orderItems as item)

        priority = 7

        if(item[productType] == 'product type 2' and item[variation] == 'variation 2'
          productType2[] = true

        if(item[productType] == 'product type 1')
          priority = 1
          brake

        if(item[productType] == 'product type 3')
          priority = 5
          brake

    endForeach

    if(count(productType2) == count(orderItems))
      priority = 3

if deliveryCountry != uk
 
    do the same as above
       

I deliberately didn't use a function

Aucun commentaire:

Enregistrer un commentaire