Skip to main content
fixed issue with first regex; added 1 characters in body
Source Link
bummzack
  • 22.7k
  • 5
  • 64
  • 87

In case of the zeroes and ones, you have to split with "", but in case of the tile-numbers this doesn't work as it would create an array entry for - and 1 when the value should be -1. But luckily you have a delimiter , which you can use.

So instead of

levelTiles = levelTiles.split("\n").join("");
levelTiles = levelTiles.split(",").join("");
tileArray = levelTiles.split("");

Use:

levelTiles = levelTiles.split("\n").join(""",");
tileArray = levelTiles.split(",");

A cleaner way to split (which also removes unnecessary white-space) could be done with a regular expression:

tileArray = levelTiles.replace(/\n\r?/g,",").split(/\s*,\s*/);

To split the Bitstring and get rid of the white-space I suggest you use this instead:

bitArray = bitString.replace(/\s+/g, "").split("");

In case of the zeroes and ones, you have to split with "", but in case of the tile-numbers this doesn't work as it would create an array entry for - and 1 when the value should be -1. But luckily you have a delimiter , which you can use.

So instead of

levelTiles = levelTiles.split("\n").join("");
levelTiles = levelTiles.split(",").join("");
tileArray = levelTiles.split("");

Use:

levelTiles = levelTiles.split("\n").join("");
tileArray = levelTiles.split(",");

A cleaner way to split (which also removes unnecessary white-space) could be done with a regular expression:

tileArray = levelTiles.split(/\s*,\s*/);

To split the Bitstring and get rid of the white-space I suggest you use this instead:

bitArray = bitString.replace(/\s+/g, "").split("");

In case of the zeroes and ones, you have to split with "", but in case of the tile-numbers this doesn't work as it would create an array entry for - and 1 when the value should be -1. But luckily you have a delimiter , which you can use.

So instead of

levelTiles = levelTiles.split("\n").join("");
levelTiles = levelTiles.split(",").join("");
tileArray = levelTiles.split("");

Use:

levelTiles = levelTiles.split("\n").join(",");
tileArray = levelTiles.split(",");

A cleaner way to split (which also removes unnecessary white-space) could be done with a regular expression:

tileArray = levelTiles.replace(/\n\r?/g,",").split(/\s*,\s*/);

To split the Bitstring and get rid of the white-space I suggest you use this instead:

bitArray = bitString.replace(/\s+/g, "").split("");
added some clarification and info about bit-array split
Source Link
bummzack
  • 22.7k
  • 5
  • 64
  • 87

In case of the zeroes and ones, you have to split with "" (which will split between every character, sobut in case of the tile-numbers this doesn't work as it would create an array entry for - and 1 will be considered two entries), but in case ofwhen the tile-numbers,value should be -1. But luckily you have a delimiter , which you can use.

So instead of

levelTiles = levelTiles.split("\n").join("");
levelTiles = levelTiles.split(",").join("");
tileArray = levelTiles.split("");

Use:

levelTiles = levelTiles.split("\n").join("");
tileArray = levelTiles.split(",");

A cleaner way to split (which also removes unnecessary white-space) could be done with a regular expression:

tileArray = levelTiles.split(/\s*,\s*/);

To split the Bitstring and get rid of the white-space I suggest you use this instead:

bitArray = bitString.replace(/\s+/g, "").split("");

In case of the zeroes and ones, you have to split with "" (which will split between every character, so - and 1 will be considered two entries), but in case of the tile-numbers, you have a delimiter , which you can use.

So instead of

levelTiles = levelTiles.split("\n").join("");
levelTiles = levelTiles.split(",").join("");
tileArray = levelTiles.split("");

Use:

levelTiles = levelTiles.split("\n").join("");
tileArray = levelTiles.split(",");

A cleaner way to split (which also removes unnecessary white-space) could be done with a regular expression:

tileArray = levelTiles.split(/\s*,\s*/);

In case of the zeroes and ones, you have to split with "", but in case of the tile-numbers this doesn't work as it would create an array entry for - and 1 when the value should be -1. But luckily you have a delimiter , which you can use.

So instead of

levelTiles = levelTiles.split("\n").join("");
levelTiles = levelTiles.split(",").join("");
tileArray = levelTiles.split("");

Use:

levelTiles = levelTiles.split("\n").join("");
tileArray = levelTiles.split(",");

A cleaner way to split (which also removes unnecessary white-space) could be done with a regular expression:

tileArray = levelTiles.split(/\s*,\s*/);

To split the Bitstring and get rid of the white-space I suggest you use this instead:

bitArray = bitString.replace(/\s+/g, "").split("");
added regex that can be used for split
Source Link
bummzack
  • 22.7k
  • 5
  • 64
  • 87

In case of the zeroes and ones, you have to split with "" (which will split between every character, so - and 1 will be considered two entries), but in case of the tile-numbers, you have a delimiter , which you can use.

So instead of

levelTiles = levelTiles.split("\n").join("");
levelTiles = levelTiles.split(",").join("");
tileArray = levelTiles.split("");

Use:

levelTiles = levelTiles.split("\n").join("");
tileArray = levelTiles.split(",");

A cleaner way to split (which also removes unnecessary white-space) could be done with a regular expression:

tileArray = levelTiles.split(/\s*,\s*/);

In case of the zeroes and ones, you have to split with "" (which will split between every character, so - and 1 will be considered two entries), but in case of the tile-numbers, you have a delimiter , which you can use.

So instead of

levelTiles = levelTiles.split("\n").join("");
levelTiles = levelTiles.split(",").join("");
tileArray = levelTiles.split("");

Use:

levelTiles = levelTiles.split("\n").join("");
tileArray = levelTiles.split(",");

In case of the zeroes and ones, you have to split with "" (which will split between every character, so - and 1 will be considered two entries), but in case of the tile-numbers, you have a delimiter , which you can use.

So instead of

levelTiles = levelTiles.split("\n").join("");
levelTiles = levelTiles.split(",").join("");
tileArray = levelTiles.split("");

Use:

levelTiles = levelTiles.split("\n").join("");
tileArray = levelTiles.split(",");

A cleaner way to split (which also removes unnecessary white-space) could be done with a regular expression:

tileArray = levelTiles.split(/\s*,\s*/);
Source Link
bummzack
  • 22.7k
  • 5
  • 64
  • 87
Loading