6 kyu

Strings: filter out the Wikipedia reference marks from text

Description
Loading description...
Strings
Filtering
Algorithms
  • Please sign in or sign up to leave a comment.
  • Madjosz Avatar

    Since you are insisting on modifying the input buffer and return it (which is not tested in any sample or fixed test) you should at least mention this in the description or the initial solution setup. I don't want to guess this from the fact that the signature doesn't declare source as const char*.

  • tolgaersoy Avatar

    This comment has been hidden.

  • almeida20 Avatar

    This comment has been hidden.

    • Madjosz Avatar

      If the input string doesn't contain any reference marks, your code just increases i until out of bounds.

      Question marked resolved by Madjosz 2 years ago
  • SunMaster Avatar

    Doing the NASM-version

    I pass the Test, and fail all on Attempt.

    Output is :

    *Actual*]: "Codewars is an educational community for computer programming. On the platform, software developers train on programming challenges known as kata.[1][2] These discrete programming exercises train a variety of skills in a variety of programming languages, and are completed within an online IDE.[3][4][5]"
    
    [Expected]: "Codewars is an educational community for computer programming. On the platform, software developers train on programming challenges known as kata. These discrete programming exercises train a variety of skills in a variety of programming languages, and are completed within an online IDE."
    
      [String]: "Codewars is an educational community for computer programming. On the platform, software developers train on programming challenges known as kata.[1][2] These discrete programming exercises train a variety of skills in a variety of programming languages, and are completed within an online IDE.[3][4][5]"
      
    

    However, it is not what I return.

    I output this to the concole just before exiting.

    Codewars is an educational community for computer programming. On the platform, software developers train on programming challenges known as kata. These discrete programming exercises train a variety of skills in a variety of         programming languages, and are completed within an online IDE.
    

    There may very well be errors in the string I return. I do however not return the string listed as actual.

  • uniapi Avatar
  • Voile Avatar
    • Needs random tests
    • So there will not be brackets with non-numbers between (i.e fake reference tags)? If that's so you should clarify it in the descriptions
  • Voile Avatar

    As mentioned below, if modifications are done in place then the function return type should be void, not char*.

  • marrakchino Avatar

    Why do we need to return a char* if the modifications are done in-place on the parameter?

    • uniapi Avatar

      Indeed! It's a standard way to return something useful and considered to be BestPractices! Here are some of string functions from the standard library that do it the similar way: strcpy: char *strcpy(char *dest, const char *src);

      strcat: char *strcat(char *dest, const char *src);

      Consider this code:

      char s[255] = "The shortest way[1]?";
      assert(!strcmp(filter_refs_out(s), "The shortest way?"));
      assert(!strcmp(filter_refs_out(strcpy(s, "Not so readable[1]?")), "Not so readable?"));
      assert(!strcmp(filter_refs_out(strcpy(s, "More compact[1]?")), "More compact?"));
      

      And this one:

      char s[255] = "The shortest way[1]?";
      filter_refs_out(s);
      assert(!strcmp(s, "The shortest way?"));
      
      strcpy(s, "Not so readable[1]?");
      filter_refs_out(s);
      assert(!strcmp(s, "Not so readable?"));
      
      strcpy(s, "More compact[1]?");
      filter_refs_out(s);
      assert(!strcmp(s, "More compact?"));
      

      The first is more convenient and more compact especially if there are dozens of them... Sure, there are better explanations and better applications than these ones!

    • Voile Avatar

      ;-)

      Question marked resolved by Voile 6 years ago