Competition time :)

Not really but going for clickbait title

What's the neatest reporter you can come up with to take a number surrounded by space chars (bonus points for any whitespace char) e.g " 5 " (5 surrounded by two spaces at each end) and just return the 5.

If the input is not considered numeric e.g "A5 ", (A,5 and two spaces) then it should return it untouched

Accidentally made this a predicate instead of a reporter, but the script should work!

I think you'll win the prize for most complicated way of doing it

But it works

Man I love javascript

The reason I compare trimmed to join (num) + is because when you set a veriable to NaN, it turns into 0.

Edit, here's a much more simplified version

Que?

2nd solution looks good

I said that because math calculations are done in javascript, so the javascript quirks still apply.

aah - got you

And it even copes with other whitespace chars

Here's essentially a single-block script doing the job:

It does handle e.g. " 5 4 " as a number (54) though, so I'm not sure if it qualifies.

Nice that it handle "5 4" (but not a requirement - this is for when I've parsed an AdventOfCode puzzle input but there is invisible whitespace surrounding numbers)

But it only handles " " and not all whitespace like @ego-lay_atman-bay so it's got 2nd prize

If that's what you want, try this one-block script:

yay i did it
it doesn't handle other whitespace characters though

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.