All challenges
Easy 0 solved 0% acceptance

Every Other Character

Keep the characters at even positions.

Problem

Build a new string from the characters of text at positions 0, 2, 4, … (every other character, starting with the first).

Implement every_other_character(text).

Input

text: The original text.

Output

Return the characters at even positions, in order.

Constraints

0 ≤ length of text ≤ 10,000

Examples

Example 1
Input:
text = "programming"

Expected output:
expected = "pormig"
Input:
std::string text = "programming";

Expected output:
std::string expected = "pormig";
Input:
string text = "programming";

Expected output:
string expected = "pormig";

Explanation

Positions 0, 2, 4, 6, 8, 10 give p, o, r, m, i, g: "pormig".

Example 2
Input:
text = "a"

Expected output:
expected = "a"
Input:
std::string text = "a";

Expected output:
std::string expected = "a";
Input:
string text = "a";

Expected output:
string expected = "a";

Explanation

Only position 0 exists: "a".

References

This challenge is adapted for CodeUtility. Follow the statement and constraints above.

Learn from others

Community solutions

No published solutions yet. Solve this challenge to share the first one.