0

With GREL is it possible to get the longest string of an array ? For example, if I have an array with 3 strings ["a","aaa","aa"], I want to obtain "aaa".

Mathieu Saby
  • 125
  • 5

1 Answers1

0

You can probably do that at the cost of a very complicated formula. It's typically to face this kind of case that Open Refine added Python (and Clojure) as scripting languages. Even if you don't know Python, you can find in two minutes the answer to the question "how to choose the longest string in list?" and simply copy and paste it (by adding a "return" instead of "print")

In this case :

return max(['a','aaa','aaaa','aa'], key=len)

EDIT

Just for the sake of the challenge, here is a possible solution with GREL.

value = "a,aa,aaaa,aa"

forEach(value.split(','), e, if(length(e)==sort(forEach(value.split(','), e, e.length()))[-1], e, null)).join(',').split(',')

enter image description here

Ettore Rizza
  • 2,800
  • 2
  • 11
  • 23