7 kyu

Alphabetize a list by the nth character

753 of 1,996edm2410
Description
Loading description...
Lists
Strings
Sorting
Arrays
Fundamentals
  • Please sign in or sign up to leave a comment.
  • PetitLu117 Avatar

    JS fork πŸ€–

    • updated to node 18, resolving this issue
    • made description language-agnostic
    • used mocha/chai assertions + lodash for randomness
    • added random tests in addition to randomized tests
    • provided inputs on failure
  • tiger43 Avatar

    Issue with problem statement

    There are inconsistencies between the problem description and the test cases.

    1. The problem statement says, "The letters should be compared case-insensitive," but the tests only pass if the sorting is case-sensitive.

    2. The the following sentence in the problem statement is redundant: "If both letters are the same, order them normally (lexicographically), again, case-insensitive". Lexicographical ordering already handles ties without needing a separate case-insensitivity clause.

    Please clarify whether the sorting should be case-sensitive or case-insensitive.

  • ptihiy Avatar

    Not worth spending time cause the description is awful.

  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • π•šπ•π•ͺ𝕒 Avatar

    There is an error in the description. It says that letters should be compared case insensitive, but the tests can only succeed if they are case-sensitive. The lexicographic sorting is also unnecessary if the letters match.

  • mohdmujtabaa Avatar

    Could some one help on "how to deal with multiple words separated by spaces". Should space be considered or not.Any further explanation to under this Kata is very much appreciated. I see many people solved the Kata in many different languages, so I must be missing something. I sorted by character at the index and then the word lexicographically, but test are failing. I followed the step to make the comparision case insensitive as well.

  • Cloud Walker Avatar

    Misleading. Its not just words, it's words separated by spaces, then the comma. And some of the words are less than n in length.

  • farhanaditya Avatar

    JS: Node v14 should be used along with its appropiate assertion tools (Mocha + Chai). Refer to this and this

  • farhanaditya Avatar

    Description should mention how to deal with multiple words separated by spaces.

  • tdm725 Avatar

    This is great but a 7? Really?

  • MobulaKuhlii Avatar

    The letters should be compared case-insensitive. If both letters are the same, order them normally (lexicographically), again, case-insensitive.

    First part doesn't hold for ruby where case does matter, second also doesn't because ties are broken by position in original array.

  • akar-0 Avatar

    (Python) I can't understand the logic when sorting "multiple words" words. First problem is that description says nothing about what is actually considerated a word here... I guess words are things separated by commas... So why :

    "Ernst von Eisenach, Oskar von Reuenthal, Anton Ferner, Ernst von Eisenach, Hildegard von Mariendorf, Karl Gustav Kempf, Adalbert von Fahrenheit, Karl Robert Steinmetz, August Samuel Wahlen, Theodor von Lucke, Siegfried Kircheis, Ulrich Kesler, Helmut Rennenkampf, Emil von Secla, Arthur von Streit, Paul von Oberstein, Reinhard von Lohengramm, Wolfgang Mittermeyer"

    should be sorted as

    "'Ernst von Eisenach, Oskar von Reuenthal, Ernst von Eisenach, Hildegard von Mariendorf, Siegfried Kircheis, Wolfgang Mittermeyer, Paul von Oberstein, Emil von Secla, Karl Gustav Kempf, August Samuel Wahlen, Anton Ferner, Helmut Rennenkampf, Arthur von Streit, Theodor von Lucke, Karl Robert Steinmetz, Ulrich Kesler, Adalbert von Fahrenheit, Reinhard von Lohengramm"

    with n = 10?

    10th letter of first three "sorted" "words" are 'i', 'e' and 'i' respectively. How could that be sorted? Unless it's actually meant not 10th letter but 10th character (in that case please call things by their names). If it is so in those three words the 10th character is a space (how should we sort between letters and spaces?), the description says " If both letters are the same, order them normally (lexicographically)". How would "Ernst..., Oskar..., Ernst..." be sorted alphabetically?

  • Blind4Basics Avatar

    Python: the first argument should be named s or strng, not list_... x)

  • Magicloud Avatar

    I think the unit test has a bug. There is no requirement on sorting two words with the same sorting character. But in unit test, it is ordered. Thus on random test, simply order by n char may fail.

  • elchroy Avatar

    This comment has been hidden.

  • user7831952 Avatar

    How are you supposed to handle multiple words having a character at "n"? In another comment, it is mentioned that such corner cases aren't tested, yet my results are failing because my ordering of multiple words with the same 'n'th character does not match the expected ordering. The expected ordering of these 'duplicates' does not seem to be based on insertion order, alphabetical order starting from the first letter, or alphabetical order starting from the nth letter. It seems really ambiguous to leave out the instructions for how to handle this corner case and then test that corner case.

  • knowlj Avatar

    Where do I enter the solution?

  • eliotsykes Avatar

    Use more descriptive parameter names in the beginning code template. list_ and n could be more descriptive and the underscore suffix is unconventional for Ruby. Suggestion: words and sort_char_position as clearer param names. Good for participants to see good naming practices in the provided code.

  • mikethecodegeek Avatar

    Hello everyone, I'm new here and this is my first Kata. Can someone please explain to me what is going on. I just finished up the code and was excited when all of the tests passed then this happened.

    Basic tests Test Passed: Value == wording, words, wordy, wordz Test Passed: Value == ha, he, hi, ho Test Passed: Value == a, ba, cat, wax, yellow, zephyr Test Passed: Value == today, are, doing, hello, you, how Test Passed: Value == wording, words, wordy, wordz Test Passed: Value == ha, he, hi, ho Test Passed: Value == a, ba, cat, wax, yellow, zephyr Test Passed: Value == today, are, doing, hello, you, how Random tests Testing for "August Samuel Wahlen, Paul von Oberstein, Emil von Secla, Karl Robert Steinmetz, Fritz Josef Bittenfeld, Ernst von Eisenach, Arthur von Streit", 10 TypeError: Object function { var i = this.length, j, k; for { j = Math.floor(Math.random() * this.length); k = this[--i];this[i] = this[j];this[j] = k; } return this; } has no method 'substring' at sortIt at Object.Test.it at Object.Test.describe

        at Object.<anonymous>
        
    

    8 Passed 0 Failed 40 Errors Process took 81ms to complete

    I'm really confused. None of this code is even anything I wrote. How do I get a typeError for something I never put in there. I'm sure there is a simple explanation I hope that someone can explain to me whats happening. Thank You

  • drhuffman12 Avatar

    I also believe the Random tests can at least sometimes be incorrect.

    The test instructions mention a primary sort by the n-th letter, but has no further sorting instructions. A comment below suggests a secondary sort of "insertion order", where "insertion order" is assumed [by me] to be 'left to right'.

    However, the "Random tests" don't appear to always follow the this primary-secondary sort order.

  • mikurubeam Avatar

    I believe some of the random test cases are incorrect:

    Testing for "Arthur von Streit, August Samuel Wahlen, Siegfried Kircheis, Karl Robert Steinmetz, Reinhard von Lohengramm, Helmut Rennenkampf, Ernst von Eisenach, Fritz Josef Bittenfeld", 2

    It should work for random inputs too - Expected: Karl Robert Steinmetz, Reinhard von Lohengramm, Helmut Rennenkampf, Siegfried Kircheis, Arthur von Streit, Ernst von Eisenach, Fritz Josef Bittenfeld, August Samuel Wahlen, instead got: Karl Robert Steinmetz, Reinhard von Lohengramm, Helmut Rennenkampf, Siegfried Kircheis, Fritz Josef Bittenfeld, Ernst von Eisenach, Arthur von Streit, August Samuel Wahlen

    Compare the Expected (top) vs mine (bottom)

    K[a]rl Robert Steinmetz, R[e]inhard von Lohengramm, H[e]lmut Rennenkampf, S[i]egfried Kircheis, A[r]thur von Streit, E[r]nst von Eisenach, F[r]itz Josef Bittenfeld, A[u]gust Samuel Wahlen

    K[a]rl Robert Steinmetz, R[e]inhard von Lohengramm, H[e]lmut Rennenkampf, S[i]egfried Kircheis, F[r]itz Josef Bittenfeld, E[r]nst von Eisenach, A[r]thur von Streit, A[u]gust Samuel Wahlen

    Specifically,

    A[rt]hur von Streit, E[rn]st von Eisenach, F[ri]tz Josef Bittenfeld

    F[ri]tz Josef Bittenfeld, E[rn]st von Eisenach, A[rt]hur von Streit

    Clearly, the correct aphabetical order, starting from the 2nd letter is [ri, rn, rt] and NOT [rt, rn, ri].

    This example test case is sorted alphabetically by second letter until there are ties. Then ties are sorted by insertion order.

    This needs to be made clear if it is the intended behavior.

  • GiacomoSorbi Avatar

    Kata upvoted, greenlit, took the liberty of adding a few extra cases myself and translated it into both Ruby and Python, if you wish to approve them :)

    [For the sake of my own curiosity, I was wondering why you would do a kata in JS and call the array "list", as it is the norm in Python: could you tell me why you used that term, if there was a particular reason?]

  • bkaes Avatar

    So, what about the corner cases? For example, if some words don't have enough letters, how should they be sorted?

  • DJTB Avatar

    Add some example test cases and I'd say it's good to go.

  • bkaes Avatar

    No example test cases :/.

  • myTerminal Avatar

    Tells me that my answer is wrong, whereas echos that the expected and actual are the same.