depth

Second largest distinct value

Write a function that returns the second largest distinct value of a list of numbers.

f 3 1 4 1 5 9

should return 5.

Hint

Remove duplicates, sort descending, then index.

Solution

f:{(desc distinct x)1}

distinct removes duplicates, desc sorts descending, and 1 indexes the second item.

Answer

f:{(desc distinct x)1}