Concatenative Programming @programming.dev Andy @programming.dev 1y ago Reverse Vowels | Re: Factor re.factorcode.org Reverse Vowels | Re: Factor
I solved that problem a little differently: factor : 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: factor : 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 ;
I solved that problem a little differently:
Maybe clearer on lemmy without the comments: