Reverse words in a string: Difference between revisions
m
→{{header|AppleScript}}
m (added whitespace to the task's preamble, changed the example text to not use quotation marks.) |
|||
Line 216:
<lang AppleScript>on run {}
unlines(map(
fire, in end will world the say Some
ice. in say Some
desire of tasted I've what From
fire. favor who those with hold I
... elided paragraph last ...
Frost Robert -----------------------")
end run
-- reverseWords :: String -> String
on reverseWords(str)
unwords(
end reverseWords
-- |reverse| :: [a] -> [a]
on
if class of xs is text then
(reverse of characters of xs) as text
Line 241:
reverse of xs
end if
end
-- |lines| :: Text -> [Text]
on
splitOn(linefeed, str)
end
-- |words| :: Text -> [Text]
on
splitOn(space, str)
end
-- ulines :: [Text] -> Text
on unlines(lstLines)
intercalate(linefeed, lstLines)
end unlines
-- unwords :: [Text] -> Text
on unwords(lstWords)
intercalate(space, lstWords)
end unwords
-- splitOn :: Text -> Text -> [Text]
on splitOn(strDelim, strMain)
set {dlm, my text item delimiters} to {my text item delimiters, strDelim}
set lstParts to text items of strMain
set my text item delimiters to dlm
end splitOn
-- interCalate :: Text -> [Text] -> Text
on intercalate(strText, lstText)
set {dlm, my text item delimiters} to {my text item delimiters, strText}
set strJoined to lstText as text
set my text item delimiters to dlm
end intercalate
--
on map(
end script▼
set lst to {}
set lng to length of xs
repeat with i from 1 to lng
set end of lst to mf's
end repeat
return lst
end map</lang>
▲ property call : f
▲ end script
{{out}}
|