Middle three digits: Difference between revisions
Content deleted Content added
→{{header|Scala}}: Marked incomplete as I think it would fail for 10100 for example. |
Keithpinson (talk | contribs) |
||
Line 716: | Line 716: | ||
middle_three_digits(0) returned: Failure, Too short</pre> |
middle_three_digits(0) returned: Failure, Too short</pre> |
||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
{{incomplete|Scala|I just noticed that if intVals contained 10100 then your output would be "10" instead of '010' I think.}} |
|||
<lang scala>/** |
<lang scala>/** |
||
* Optionally return the middle three digits of an integer. |
* Optionally return the middle three digits of an integer. |
||
Line 736: | Line 735: | ||
intVals map (middleThree(_)) map { |
intVals map (middleThree(_)) map { |
||
case None => "No middle three" |
case None => "No middle three" |
||
case Some(v) |
case Some(v) => f"${v}%03d" // Format the value, force leading zeroes |
||
case Some(v) => v.toString |
|||
} mkString("\n") |
} mkString("\n") |
||
</lang> |
</lang> |