string sorting
Given a string as an input (which can be any acceptable/convenient format in your language), implement pendulum encoding. The test cases are split into individual items (which aren't quoted) for a visually appealing explanation.
## How do I do that?
The current **iteration index** starts at `0`.

* If the iteration index is even, append the current item onto the output string.
* If the iteration index is odd, prepend the current item onto the output string.

## An example
The input is [a b c d e f g].
Note that the letters a-g are individual one-character strings, to prevent confusion from the iteration index.
N: the iteration index

N:0 Out:      [a]
N:1 Out:    [b a]
N:2 Out:    [b a c]
N:3 Out:  [d b a c]
N:4 Out:  [d b a c e]
N:5 Out:[f d b a c e]
N:6 Out:[f d b a c e g]
The output should be `[f d b a c e g]`.
# Another example
The input is [u d l n u e m p].

N:0 Out:        [u]
N:1 Out:      [d u]
N:2 Out:      [d u l]
N:3 Out:    [n d u l]
N:4 Out:    [n d u l u]
N:5 Out:  [e n d u l u]
N:6 Out:  [e n d u l u m]
N:7 Out:[p e n d u l u m]
## Test cases
[Here](https://tio.run/##lVLNaoQwEL77FHNZMBhl22OXLeToZdmjyxJK6o5LQKONkV767naibbQUSp1LyMz3MzMJ2lqZe4p9aXXnxjHq0NyGemjiq@QgOLwwSJ9BHKJV5fJRzMXcFyOg2IFun96tdhgLxpeUqeOvq66mw0cOFht4hOMR9l59B6Lz6llA@Ah@BXlBksD1Qq45JPDADgHp7ICzxtni3yLE9zLiW2QCToxltiJMtGLSKvaMUI3ShvYSIGHkZTWKv/KS3zjyit8lY/znDn4T5Lpb@AdBya2EuSW5hSA3OyjyIB@5JmT0KqfWpIPRb/RKDnuXlqpHqGzb0B@gZO@ycfwE)'s a sample program doing this encoding.

Take note that the characters in the string aren't always unique.
Your output *has* to be flattened.

[a,b,c,d,e,f,g]   -> [f,d,b,a,c,e,g]
[]                -> []
[a]               -> [a]
[a,b,c,d]         -> [d,b,a,c]
[a,b]             -> [b,a]
[a,b,d]           -> [b,a,d]
[a,b,a,c,b,c]     -> [c,c,b,a,a,b]
[a,a,b,b,c,c]     -> [c,b,a,a,b,c]
[u,d,l,n,u,e,m,p] -> [p,e,n,d,u,l,u,m]
Top Answer
# [APL (Dyalog Extended)], 11 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?") ([SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set"))


[Try it online!][TIO-k88l7mbf] (Empty case works offline, but TIO hasn't been updated.)

`-\` alternating sum

`` `∘`` of

`⍳` **ɩ**ndices

`∘` of

`≢` the length

`⍋` graded (indices that would sort)

`⍛` before

`⊇` being used to select from

`⊢` the argument

[APL (Dyalog Extended)]: https://github.com/abrudz/dyalog-apl-extended
[TIO-k88l7mbf]: https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/Xzcm4VHHjEe9m0Fk56JHvd2Pemc/6mp/1LXof9qjtgmPevsedTU/6l3zqHfLofXGj9omPuqbGhzkDCRDPDyD/6cpqCcmJaekpqWrc6Up6KgngiiwEJQBpWDcxOSkZAgzMSkpGcIsTcnJK03NLVAHAA "APL (Dyalog Extended) – Try It Online"
Pendulum Encoding
Trying out some emoji. `:D` -> :D `;)` ;) `:)` :) `:(` :( `;(` ;( `:/` :/ 
A-ee replying to Jack Douglas
@JackDouglas ^
A-ee replying to ajc2
@ajc2 Fixed by only allowing characters in the array.
Jack Douglas
@A-ee ^^^^
will the array items be a fixed type (like ints) or can they be any type
A-ee replying to David
No, the check is based on the *iteration index* and not the *current item*, because the encoding should work with lists of any type. I'd try to improve the spec. (BTW, "golf" is basically problem solving.)
@liek Me again! `o/` If evens are *a*ppended (come at end), and odds are *pre*pended (come at beginning), shouldn't output be: `[7 5 3 1 2 4 6]`? I only ask! (I don't "golf", btw — I only admire those who do!)