17
2
Ah, yet another of my selfish uses of this Stack.
Being a Chromebook owner, I'm a frequent user of the Ace IDE, the editor used by Cloud9. It has lots of tools for dealing with excess whitespace, but it notably lacks one: clearing empty lines.
Your mission today is, given an input from a place I can copy-paste to [;)
], output something identical, save all spaces and tabulators on otherwise empty lines.
I'll give some examples, with #
s representing whitespace characters to be removed.
INPUT 1:
if (this.Color !== 'blue') {
##
this.Color = 'blue';
}
OUTPUT:
if (this.Color !== 'blue') {
[empty line]
this.Color = 'blue';
}
INPUT 2:
function outputSomething(times) {
for (var iter = 0; iter < times; iter++) {
console.log('"# # " represents a tabulator');
// This is a comment
# #
}}
OUTPUT:
function outputSomething(times) {
for (var iter = 0; iter < times; iter++) {
console.log('"# # " represents a tabulator');
// This is a comment
[empty line]
}}
INPUT 3:
var x = 'Do you prefer spaces or tabs?';
var y = 'I\'m using both here. Sue me.';
# # ####
console.log(x + ' ' + y);
OUTPUT:
var x = 'Do you prefer spaces or tabs?';
var y = 'I\'m using both here. Sue me.';
[empty line]
console.log(x + ' ' + y);
You may process the input however you like. Output wherever, so long as I can copy-paste from it [;)
].
Standard loopholes apply, shortest answer in bytes wins!
Do we have to leave an empty line where it says
[empty line]
, or no line at all? – Leaky Nun – 2017-04-26T13:40:31.7906Oh, and, before anyone does it, no getting into the 'spaces vs tabulators' holy war. Doing that gets your answers nuked with a 10,000 byte penalty :P – Papayaman1000 – 2017-04-26T13:40:36.340
@LeakyNun an empty line, save for a newline character. – Papayaman1000 – 2017-04-26T13:40:56.933
What does
#
in your examples mean? – Leaky Nun – 2017-04-26T13:41:16.363@LeakyNun
#
is visible shorthand for a space, while#
with a space in front of it is for a tabulator. – Papayaman1000 – 2017-04-26T13:42:06.833So the line in
INPUT 3
is[space][tab][tab][space][space][space]
? – Leaky Nun – 2017-04-26T13:42:58.870@LeakyNun
[tab][tab][space][space][space][space]
. – Papayaman1000 – 2017-04-26T13:44:05.7971And are all these clarifications necessary? Just nuke spaces and tabulators on lines that have no other characters. – Papayaman1000 – 2017-04-26T13:44:37.260
Is a trailing newline in the output ok? – Business Cat – 2017-04-26T13:49:54.187
@BusinessCat Yes. – Papayaman1000 – 2017-04-26T13:50:30.143
Is it okay to nuke other whitespace charcters as well? – HyperNeutrino – 2017-04-26T13:51:19.023
@HyperNeutrino Absolutely! I was mainly restricting it to ASCII to account for languages that can only process such. – Papayaman1000 – 2017-04-26T13:52:23.070
1Can we assume that the input will not contain trailing whitespace on any lines (except the all-whitespace ones, obviously)? None of the examples do. – ETHproductions – 2017-04-26T14:26:47.830
1If a line containing non-whitespace has trailing whitespace, is it ok to strip that whitespace? – Digital Trauma – 2017-04-26T15:42:58.813
@DigitalTrauma I suppose, why not. – Papayaman1000 – 2017-04-26T15:54:15.407
perhaps, this answer may interest you? https://meta.stackexchange.com/a/294870/300395 @Papayaman1000 this will let you put tabs in
– Rohan Jhunjhunwala – 2017-04-26T20:16:16.117@mathjunkie The challenge could be called "make empty lines empty." – Esolanging Fruit – 2017-04-27T00:09:44.630