The Selkie-Loom of Brindlecove
On the storm-beaten shore of Brindlecove, the Selkie weavers work a great loom of sealskin and driftwood. Each tide-charm they weave is woven from two spools of enchanted thread, and the charm holds only if the strands are laid in strict alternation. The Weavers' Circle offers a bounty of pearls to whoever can work out the laying order for any pair of spools.
Write weaveSpools(left, right).
leftis a list of strings, the threads on the left spool, in the order they come off it.rightis a list of strings, the threads on the right spool, in the order they come off it.- Either list may be empty, and the two lists may have different lengths.
Return a new list of strings: the first thread of left, then the first thread of right, then the second of left, then the second of right, and so on, alternating. Once one list has no threads left, append all remaining threads of the other list in their original order. If both lists are empty, return an empty list.
examples
- case 1
left of ["gold", "grey"], right of ["blue", "black"]["gold", "blue", "grey", "black"] - case 2
left of ["gold", "grey", "green"], right of ["blue"]["gold", "blue", "grey", "green"]: the right spool runs out, so the rest of the left follows in order - case 3
left of [], right of ["red", "rust"]["red", "rust"]
- reward
- 140 XP
- signature
weaveSpools
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- equal lengths
- left longer
- right longer
- left empty
- right empty
- both empty
- repeated threads kept
- single each