Skip to content

Latest commit

 

History

History

05-challenge

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Challenge 05

[The elves walk into work early on the morning of December 5th. A sign that reads "we're all about passion, not just paychecks" hangs above the entrance to the factory floor.]

It's been a tough year for Santa's workshop. The elves are a little behind schedule on getting Santa his list. Santa really really likes to see the full list of names far in advance of Christmas Eve when he makes his deliveries.

Normally the elves get lists like this

const badList = ['Tommy', 'Trash', 'Queen Blattaria' /* ... many more ... */]
const goodList = ['Jon', 'David', 'Captain Spectacular' /* ... many more ... */]

And they copy-pasta all the values into a TypeScript type to provide to Santa like this

type SantasList = ['Tommy', 'Trash', 'Queen Blattaria', 'Jon', 'David', 'Captain Spectacular' /* ... many more ... */]

But there's a problem... There's one elf on the team, Frymagen, that constantly reminds the others how incredible his Vim skills are. So he has always done it in years past. However this year, Frymagen got one of those MacBook Pros without the escape key and his Vim speed is drastically reduced. We need to find a better way to get Santa his list.

Let's implement SantasList such that it can be passed the types for the badList and goodList and it will return a TypeScript tuple with the values of both lists combined.

Expected Behavior

const badBoys = ['tommy', 'trash'] as const
const goodGuys = ['bash', 'tru'] as const

type SantasList01 = SantasList<typeof badBoys, typeof goodGuys>
// ['tommy', 'trash', 'bash', 'tru']

type SantasList02 = SantasList<[], []>
// []

type SantasList03 = SantasList<[], ['trash']>
// ['trash']

type SantasList04 = SantasList<['john'], ['ashley', 'elliot', 'ziltoid']>
// ['john', 'ashley', 'elliot', 'ziltoid']

type SantasList05 = SantasList<['1', 2, '3'], [false, boolean, '4', ['nested']]>
// ['1', 2, '3', false, boolean, '4', ['nested']]

type SantasList06 = SantasList<null, undefined>
// Throws a TypeScript error

Prompt by Dimitri Mitropoulos of MiTS