dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
83 lines
1.7 KiB
Markdown
83 lines
1.7 KiB
Markdown
---
|
|
id: 69f35a5bb823ed620fcb7cbc
|
|
title: "Challenge 283: String Zipper"
|
|
challengeType: 29
|
|
dashedName: challenge-283
|
|
---
|
|
|
|
# --description--
|
|
|
|
Given two strings, return a new string that interleaves their characters one at a time. If one string is longer, append the remaining characters at the end.
|
|
|
|
Begin with the first character of the first string.
|
|
|
|
# --hints--
|
|
|
|
`zip_strings("abc", "123")` should return `"a1b2c3"`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(zip_strings("abc", "123"), "a1b2c3")`)
|
|
}})
|
|
```
|
|
|
|
`zip_strings("acegikmoqsuwy", "bdfhjlnprtvxz")` should return `"abcdefghijklmnopqrstuvwxyz"`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(zip_strings("acegikmoqsuwy", "bdfhjlnprtvxz"), "abcdefghijklmnopqrstuvwxyz")`)
|
|
}})
|
|
```
|
|
|
|
`zip_strings("day", "night")` should return `"dnaiyght"`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(zip_strings("day", "night"), "dnaiyght")`)
|
|
}})
|
|
```
|
|
|
|
`zip_strings("python", "javascript")` should return `"pjyatvhaosncript"`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(zip_strings("python", "javascript"), "pjyatvhaosncript")`)
|
|
}})
|
|
```
|
|
|
|
`zip_strings("feCdCm", "reoeap")` should return `"freeCodeCamp"`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(zip_strings("feCdCm", "reoeap"), "freeCodeCamp")`)
|
|
}})
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```py
|
|
def zip_strings(a, b):
|
|
|
|
return a
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```py
|
|
def zip_strings(a, b):
|
|
result = ""
|
|
for i in range(max(len(a), len(b))):
|
|
if i < len(a):
|
|
result += a[i]
|
|
if i < len(b):
|
|
result += b[i]
|
|
return result
|
|
```
|