You must log in or register to comment.
I solved that problem a little differently:
: reverse-vowels-2 ( str -- str' ) [ clone ] [ >lower [ vowel? ] find-all [ values reverse ] [ keys ] bi ] bi ! str vowels idxs [ ! str | vowel idx pick dupd nth ! str | vowel idx orig 1string upper? ! str | vowel idx t/f swapd [ ch>upper ] when ! str | idx vowel set-nth-of ! str' ] 2each ! str' ;
Maybe clearer on lemmy without the comments:
: reverse-vowels-2 ( str -- str' ) [ clone ] [ >lower [ vowel? ] find-all [ values reverse ] [ keys ] bi ] bi [ pick dupd nth 1string upper? swapd [ ch>upper ] when set-nth-of ] 2each ;