Permutations: Difference between revisions
m
→{{header|AppleScript}}: Slight reorganisation, updated primitives
(→{{header|Scala}}: Simplify collections library example) |
m (→{{header|AppleScript}}: Slight reorganisation, updated primitives) |
||
Line 442:
(Functional ES5 version)
<lang AppleScript>
permutations({"aardvarks", "eat", "ants"})▼
end run▼
on permutations(xs)
script firstElement
Line 468 ⟶ 462:
end if
end permutations
-- TEST
on run
▲ permutations({"aardvarks", "eat", "ants"})
▲end run
Line 486 ⟶ 488:
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
set lng to length of xs
set lst to {}
repeat with i from 1 to lng
set end of lst to
end repeat
return lst
end tell
end map
-- foldl :: (a -> b -> a) -> a -> [b] -> a
on foldl(f, startValue, xs)
set v to startValue
set
repeat with i from 1 to lng▼
▲ repeat with i from 1 to lng
end repeat
▲ set v to mf's lambda(v, item i of xs, i, xs)
end foldl
Line 556 ⟶ 559:
end script
end if
end mReturn</lang>
{{Out}}
|