View Problem

Rotate a list

Given a list ["apple", "orange", "grapes", "bananas"], rotate it by removing the first item and placing it on the end to yield ["orange", "grapes", "bananas", "apple"]
ExpandDiskEdit
erlang
N = 1, {Left, Right} = lists:split(N, List), Result = Right ++ Left,
ExpandDiskEdit
erlang
N = 1, Result = rotate(N, List),
ExpandDiskEdit
fsharp
let rotate list n =
if n <= 0 then
list
else
let (left, right) = split_at list (n - 1)
right @ left

// ------

let result = (rotate fruit 1)
ExpandDiskEdit
fantom
list := ["apple", "orange", "grapes", "bananas"]
list.add(list.removeAt(0))
ExpandDiskEdit
groovy 1.5.6
first = items.head()
items = items.tail() + first
ExpandDiskEdit
groovy
items = items[1..-1] + items[0]
ExpandDiskEdit
groovy
items = items + items.remove(0)

Submit a new solution for erlang, fsharp, fantom, or groovy
There are 16 other solutions in additional languages (clojure, cpp, csharp, haskell ...)