Back to Type Challenges

README

questions/00847-hard-string-join/README.md

latest1.5 KB
Original Source
<!--info-header-start--><h1>String Join </h1><blockquote><p>by Matt Davis <a href="https://github.com/tl-matt-davis" target="_blank">@tl-matt-davis</a></p></blockquote><p><a href="https://tsch.js.org/847/play" target="_blank"></a> </p><!--info-header-end-->

Create a type-safe string join utility which can be used like so:

ts
const hyphenJoiner = join('-')
const result = hyphenJoiner('a', 'b', 'c'); // = 'a-b-c'

Or alternatively:

ts
join('#')('a', 'b', 'c') // = 'a#b#c'

When we pass an empty delimiter (i.e '') to join, we should concat the strings as they are, i.e:

ts
join('')('a', 'b', 'c') // = 'abc'

When only one item is passed, we should get back the original item (without any delimiter added):

ts
join('-')('a') // = 'a'
<!--info-footer-start-->

<a href="../../README.md" target="_blank"></a> <a href="https://tsch.js.org/847/answer" target="_blank"></a> <a href="https://tsch.js.org/847/solutions" target="_blank"></a> <!--info-footer-end-->