6 kyu

"TRaduttore".tr( [ "u", "tt" ] , "it" )

Description
Loading description...
Strings
Arrays
Fundamentals
  • Please sign in or sign up to leave a comment.
  • flaco Avatar

    the fact that toList can also contain integers is not mentioned in the description. i would either remove this test case or add the special case of integers to the discription.

  • akar-0 Avatar

    I'm getting a weird error on only one test case, the same if I return 'this' unchanged: No match, should return original string - Expected: 'H}[[() Y()u H#ppy K#+# S()[v}r', instead got: [String: 'H}[[() Y()u H#ppy K#+# S()[v}r']

    Is this correct? If so, could I get an explanation? A (dumb) workaround is returning directly 'H}[[() Y()u H#ppy K#+# S()[v}r'

  • FArekkusu Avatar

    The suggestion below is actually an issue.

  • Unnamed Avatar

    There are many solutions that iterate the pairs sequentially. How about some tests like 'abc' => 'bcd'?

  • ErikAGriffin Avatar

    Erm.. No match, should return original string - Expected: H}[[() Y()u H#ppy K#+# S()[v}r, instead got: "H}[[() Y()u H#ppy K#+# S()[v}r"

    I'm returning the original string in that case..

  • eccos Avatar

    I'm having a hard time getting the special character tests to work. I believe the parens in the first special chars test is what is screwing me up. The argument is: ( H}[[() Y()u H#ppy K#+# S()[v}r )

    But when I assign "this" to another variable... I get: H}[[() Y()u H#ppy K#+# S()[v}r

    Notice the opening/closing parens are missing.

    Can anyone point me in the right direction on how to account for this scenario?

    P.S. Is it ok for me to post my code here?

    • ZozoFouchtra Avatar

      You're right, the tested string there is H}[[() Y()u H#ppy K#+# S()[v}r (without outter parens). Is then tested against various fromList,toList, eg:

      str.tr("}[#+", "elat" )
      str.tr(["()","#+#","}[["], ["o","ata","ell"] )
      str.tr(["^.*$","[a-z]","(\w|\s)"], ["$","_","x"] )
      

      ...and so on

      hope it helps.

      P.S. If you want to post your code you should mark it as spoiler ( you'll can no more read it but warriors who have solved it will can.)

    • ZozoFouchtra Avatar
      1. concerning outer parens, i don't remember why i put them around the string. If it troubled you maybe others were (or will be) troubled too, so i remove them (now).
      2. about your code, i see you use a escSpecialCh when toList is defined, not when toList is undefined. Are you sure there will be no special chars in fromList when toList is undefined ? (hint: the answer is no, you shouldn't be sure!)

      May the Code be with you

      Question marked resolved by ZozoFouchtra 10 years ago
    • eccos Avatar
      1. Yea, I figured that out shortly after I posted that comment, so I deleted it. At first I thought I was somehow causing a memory leak or something that was producing garbage, but then I saw that you were actually trying to help us by displaying the string. It threw me off because you didn't do that with the other tests.

      2. Oh... My... God... I don't even know how I didn't notice that.

      Thank you very much for your help Zozo

  • tdolsen Avatar

    Playing with RegExp and escaping is fun, but also a hugh kidney stone. Oh man, I spent some agonizing minutes passing this stuff.

    I also see my solution wasn't as elegant as others. Made the kidney stone even bigger.

  • Sakes Avatar

    I don't think tr is a good name for this method. Makes me think of html tag. What about naming the method "trans" or "translate"?

  • wthit56 Avatar

    Nice and straightforward. Passed all the tests (went with a regex/replace-function solution). Couldn't get the "Last words" to log, though?

    • ZozoFouchtra Avatar

      "Last Words" console.logged after all test-cases.

    • wthit56 Avatar

      Oh, cool. Still not seeing anything, though:

      (copy/pasted from log frame)

      And "Last words" were : ...
      @()()d... ...l|_|[|<!".tr( "@[", "Gc" ).tr(["()","|_|","|<"],"ouk").tr(".")
      = > 
      
    • ZozoFouchtra Avatar

      Oh, oh! It does seem that your solution fails to translate the "Last words". Should I include them as a "Last test" ?

    • wthit56 Avatar

      Probably should, yeah. Or include the same edge cases in other tests.

      Godd it figured out, now. It was the "." that was tripping me up. Best add that (and the "|" too?) to some tests.

      Thanks for your help.

    • ZozoFouchtra Avatar

      Ok. I added some more tests about some special characters more ( |, *, . ). Added the " Last test " too ( with a message-error ..mhm.. not so helpful )