Domanda

New to SML and looking for a little assistance with a list question. Basically I need to create a list that is greater than variable X.

Example:

test(5,[13,2,4,17,8]) 

Expected Result: (13,17,8)

I know that I can either do this by writing two separate functions, one that determines the value is less than x and then runs through the list. Or I can try to and do it all in one function.

Any help would be appreciated.

È stato utile?

Soluzione

You can use filter to filter out elements of [13,2,4,17,8] that are greater than 5.

> List.filter (fn x => x > 5) [13,2,4,17,8];
val it = [13, 17, 8] : int LIST.list
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top