Skip to content

Commit

Permalink
feat: 'Short Long Short'
Browse files Browse the repository at this point in the history
Add 'Short Long Short' kata
  • Loading branch information
marcobiedermann committed Jul 19, 2020
1 parent 625572d commit 0416eb3
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
12 changes: 12 additions & 0 deletions kata/8 kyu/short-long-short/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import solution from '.';

describe('solution', () => {
it('should join strings based on their length', () => {
expect.assertions(4);

expect(solution('45', '1')).toStrictEqual('1451');
expect(solution('13', '200')).toStrictEqual('1320013');
expect(solution('Soon', 'Me')).toStrictEqual('MeSoonMe');
expect(solution('U', 'False')).toStrictEqual('UFalseU');
});
});
5 changes: 5 additions & 0 deletions kata/8 kyu/short-long-short/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function solution(a: string, b: string): string {
return a.length < b.length ? a + b + a : b + a + b;
}

export default solution;
52 changes: 52 additions & 0 deletions kata/8 kyu/short-long-short/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# [Short Long Short](https://www.codewars.com/kata/50654ddff44f800200000007)

Given 2 strings, `a` and `b`, return a string of the form short+long+short, with the shorter string on the outside
and the longer string on the inside. The strings will not be the same length, but they may be empty ( length `0` ).

For example:

```javascript
solution('1', '22'); // returns "1221"
solution('22', '1'); // returns "1221"
```

```typescript
solution('1', '22'); // returns "1221"
solution('22', '1'); // returns "1221"
```

```coffeescript
solution("1", "22") # returns "1221"
solution("22", "1") # returns "1221"
```

```ruby
solution("1", "22") # returns "1221"
solution("22", "1") # returns "1221"
```

```elixir
solution("1", "22") # returns "1221"
solution("22", "1") # returns "1221"
```

```csharp
ShortLongShort.Solution("1", "22"); // returns "1221"
ShortLongShort.Solution("22", "1"); // returns "1221"
```

```python
solution("1", "22") # returns "1221"
solution("22", "1") # returns "1221"
```

```php
shortLongShort("1", "22") // returns "1221"
shortLongShort("22", "1") // returns "1221"
```

---

## Tags

- Algorithms

0 comments on commit 0416eb3

Please sign in to comment.