简体   繁体   中英

Greatest Value Decision

I am writing function to give greatest value from list of values. My question is being what if all values are being the same? For examples,

30,29,34,45

Easy. Greatest value is 45. Now,

20,20,20,20

Is greatest value here is 20? Or is there no greatest value? I am confused about this.

This is important for me because I have to removing one element which is greatest value and these are money amounts so very important I not dong this wrong as then customer bill will be wrong.

In all languages I know, the buildin max will returns 20 . So it is commons that the greatest would be 20 . A basic algorithm looks like this:

let result = first element of list
foreach number in list
    if number is greater than result
        result = number

return result

Now, you will have to check if you have to remove the one greatest value or all of them. We cannot decice this for you or your client. Tips, ask them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM