Files
freeCodeCamp/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/69f35a5bb823ed620fcb7cbc.md
T

70 lines
1.4 KiB
Markdown

---
id: 69f35a5bb823ed620fcb7cbc
title: "Challenge 283: String Zipper"
challengeType: 28
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--
`zipStrings("abc", "123")` should return `"a1b2c3"`.
```js
assert.equal(zipStrings("abc", "123"), "a1b2c3");
```
`zipStrings("acegikmoqsuwy", "bdfhjlnprtvxz")` should return `"abcdefghijklmnopqrstuvwxyz"`.
```js
assert.equal(zipStrings("acegikmoqsuwy", "bdfhjlnprtvxz"), "abcdefghijklmnopqrstuvwxyz");
```
`zipStrings("day", "night")` should return `"dnaiyght"`.
```js
assert.equal(zipStrings("day", "night"), "dnaiyght");
```
`zipStrings("python", "javascript")` should return `"pjyatvhaosncript"`.
```js
assert.equal(zipStrings("python", "javascript"), "pjyatvhaosncript");
```
`zipStrings("feCdCm", "reoeap")` should return `"freeCodeCamp"`.
```js
assert.equal(zipStrings("feCdCm", "reoeap"), "freeCodeCamp");
```
# --seed--
## --seed-contents--
```js
function zipStrings(a, b) {
return a;
}
```
# --solutions--
```js
function zipStrings(a, b) {
let result = '';
const len = Math.max(a.length, b.length);
for (let i = 0; i < len; i++) {
if (i < a.length) result += a[i];
if (i < b.length) result += b[i];
}
return result;
}
```