Skip to main content
Code Review

Return to Answer

deleted 5 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

No good idea about the concern of reversing the list twice. But you may

  1. letLet you inner function return a List instead of a string thus having less conversions from list to string and string to list.

  2. changeChange your match to the following pattern (not tested):

    case " " :: tail => removePreString(tail) case _ => _

     case " " :: tail => removePreString(tail)
     case _ => _
    

I just realize you could also use on a list def dropWhile(p: (A) ⇒ Boolean): List[A]def dropWhile(p: (A) ⇒ Boolean): List[A] which drops longest prefix of elements that satisfy a predicate. You could then chain dropWhile not a space | reverse | dropwhile not a space | reverse...

No good idea about the concern of reversing the list twice. But you may

  1. let you inner function return a List instead of a string thus having less conversions from list to string and string to list.

  2. change your match to the following pattern (not tested):

    case " " :: tail => removePreString(tail) case _ => _

I just realize you could also use on a list def dropWhile(p: (A) ⇒ Boolean): List[A] which drops longest prefix of elements that satisfy a predicate. You could then chain dropWhile not a space | reverse | dropwhile not a space | reverse...

No good idea about the concern of reversing the list twice. But you may

  1. Let you inner function return a List instead of a string thus having less conversions from list to string and string to list.

  2. Change your match to the following pattern (not tested):

     case " " :: tail => removePreString(tail)
     case _ => _
    

I just realize you could also use on a list def dropWhile(p: (A) ⇒ Boolean): List[A] which drops longest prefix of elements that satisfy a predicate. You could then chain dropWhile not a space | reverse | dropwhile not a space | reverse...

Source Link
pgras
  • 271
  • 1
  • 6

No good idea about the concern of reversing the list twice. But you may

  1. let you inner function return a List instead of a string thus having less conversions from list to string and string to list.

  2. change your match to the following pattern (not tested):

    case " " :: tail => removePreString(tail) case _ => _

I just realize you could also use on a list def dropWhile(p: (A) ⇒ Boolean): List[A] which drops longest prefix of elements that satisfy a predicate. You could then chain dropWhile not a space | reverse | dropwhile not a space | reverse...

default

AltStyle によって変換されたページ (->オリジナル) /