I have string 'test1' and allowed values 'test1 test2 test3. Is a function to return string if it is in array of values to avoid complicated ifs or cases?
'test1'.function(['test1', 'test2', 'test3']) => test1
'test2'.function(['test1', 'test2', 'test3']) => test2
'test5'.function(['test1', 'test2', 'test3']) => nil
Regards
Aucun commentaire:
Enregistrer un commentaire