Truncate-a-string algorithm challenge wording


On this challenge, there is some wording that I don’t quite understand based on one of the expected results. Part 1 of the challenge is clear. no confusion on this part.

Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a … ending.

Note that inserting the three dots to the end will add to the string length

Part 2 of the challenge is this:

However, if the given maximum string length num is less than or equal to 3, then the addition of the three dots does not add to the string length in determining the truncated string.

But look at this expected result.
truncateString(“A-”, 1) should return “A…”.

Does this result fall into part 2 of the challenge definition? If it does, why are we
adding to the string length?

Sorry, I am just confused by the challenge description and looking at the expected outcomes.


The wording is not extremely clear, but looking at the expected outcomes might indeed help.

truncateString(“A-tisket a-tasket A green and yellow basket”, 11)
should return “A-tisket…”

Num is set to 11, therefore greater than 3, and the return string accounts for the three dots in the string length.

"A-tisket...".length is indeed 11

Looking instead at the other example

truncateString(“A-”, 1)
should return “A…”.

Num is set to 1, and the return string does not account for the three dots.

"A…".length is indeed 4, while "A".length is the requested 1.

Basically, it is the second argument num and its length that matters, not the length of the string itself. The three dots are added either way, but they configure in the computation of the string length only if num is greater than 3.

Hope it is of some help.


Thank you. I think I will now be able to write the algorithm with your help.


Glad to be of some assistance :grinning:


Spoiler Alert: This code works and Function Description is worded differently from Algorithm specifications.

** Function: Truncates a String. 1st argument is a string, 2nd argument is string's 
**  maxLength. 
** If string's size is larger than 2nd argument: maxLength, the string will be truncated
**   If maxLength > 3 truncate string at maxLength less 3 characters and add '...' to 
**     string's end.
**   Else truncate string at maxLength and add '...' to string's end.
** Otherwise String does not require truncation.
** @function truncateString
** @summary  Takes a string and a Multiplier to concatenate itself. Return "" if Multiplier < 
**     1
** @param 	{string} str
** @param   {number} multiplier
** @returns {string} string concatenation
function truncateString(str, maxLength) {
	'use strict';
	var result = "";
  var strSize = str.length;
  if (strSize > maxLength) {
    if (maxLength > 3) {
      result = str.slice(0, maxLength - 3) + "...";
    } else {
      result = str.slice(0, maxLength) + "...";
  else {
    result = str;
  return result;


FYI - You can surround your code with [spoiler] and [/spoiler] tags to blur out a solution.


thank you, i will edit with those appropriate tags.