mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-21 03:41:28 +02:00
Optimized cleanup_path() and list_rotate()
This commit is contained in:
@@ -432,7 +432,14 @@ function reverse(x) =
|
||||
function list_rotate(list,n=1) =
|
||||
assert(is_list(list)||is_string(list), "Invalid list or string.")
|
||||
assert(is_finite(n), "Invalid number")
|
||||
let (elems = select(list,n,n+len(list)-1))
|
||||
let (
|
||||
ll = len(list),
|
||||
n = ((n % ll) + ll) % ll,
|
||||
elems = [
|
||||
for (i=[n:1:ll-1]) list[i],
|
||||
for (i=[0:1:n-1]) list[i]
|
||||
]
|
||||
)
|
||||
is_string(list)? str_join(elems) : elems;
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user