With python, I can slice an array or string using brackets and a colon. And using the optional "step" parameter I can get every second (or third, fourth, etc) array item. I just add a second colon followed by the number 2 (or 3, or 4, etc). For example:
#slicing with python
myString = "Examples"
myString[0:6] #returns "Exampl"
myString[0:6:2] #returns "Eap"
With arcade, I know how to perform a basic string slice
//slicing with Arcade
var myString = "Examples"
Concatenate(Slice(Split(myString,""), 0, 6)) //returns "Exampl"
I'm not sure how to get every second letter with Arcade, like the python step parameter does. At least not in a single line.
var myString = "Examples"
//i know the below won't work, but is something like this possible?
Concatenate(Filter(Slice(Split(myString,""), 0, 6), index % 2 == 0))
I know I could set up a for loop to get the desired result, but I'm curious if it can be achieved in a single line without a For loop. Any ideas?
If you throw that loop into a function, it's technically a one-liner when you actually execute it? Not great, though.
var myString = "Examples"
function Step(arr, step) {
var out_array = []
for (var a in arr) {
if (a % step == 0) {
Push(out_array, arr[a])
}
}
return out_array
}
return Concatenate(Step(Slice(Split(myString, ""), 0, 6), 2))