Files
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.0 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6925e2068081f40f549ced1b Challenge 137: Snowflake Generator 28 challenge-137

--description--

Given a multi-line string that uses newline characters (\n) to represent a line break, return a new string where each line is mirrored horizontally and attached to the end of the original line.

  • Mirror a line by reversing all of its characters, including spaces.

For example, given "* \n *\n* ", which logs to the console as:

* 
 *
* 

Return "* *\n ** \n* *", which logs to the console as:

*  *
 ** 
*  *

Take careful note of the whitespaces in the given and returned strings. Be sure not to trim any of them.

--hints--

generateSnowflake("* \n *\n* ") should return "* *\n ** \n* *".

assert.equal(generateSnowflake("* \n *\n* "), "*  *\n ** \n*  *");

generateSnowflake("X=~") should return "X=~~=X".

assert.equal(generateSnowflake("X=~"), "X=~~=X");

generateSnowflake(" X \n v \nX--=\n ^ \n X ") should return " X X \n v v \nX--==--X\n ^ ^ \n X X ".

assert.equal(generateSnowflake(" X  \n  v \nX--=\n  ^ \n X  "), " X    X \n  v  v  \nX--==--X\n  ^  ^  \n X    X ");

generateSnowflake("* *\n * * \n* * *\n * * \n* *") should return "* ** *\n * * * * \n* * ** * *\n * * * * \n* ** *".

assert.equal(generateSnowflake("*   *\n * * \n* * *\n * * \n*   *"), "*   **   *\n * *  * * \n* * ** * *\n * *  * * \n*   **   *");

generateSnowflake("* -\n * -\n* -") should return "* -- *\n * -- * \n* -- *".

assert.equal(generateSnowflake("*  -\n * -\n*  -"), "*  --  *\n * -- * \n*  --  *");

--seed--

--seed-contents--

function generateSnowflake(crystals) {

  return crystals;
}

--solutions--

function generateSnowflake(crystals) {
  const lines = crystals.split("\n");

  const mirroredLines = lines.map(line => {
    const reversed = line.split("").reverse().join("");
    return line + reversed;
  });

  return mirroredLines.join("\n");
}