#Compressing String Arrays
Compressing String Arrays
Introduction
##Introduction
IfIf you have an array of strings in your code, the most obvious way to compress it would be to run each string through Oc
individually. For the purposes of this tip, we'll be working with the array ["lollipop","marshmallow","nougat","oreo"]
, which weighs in at 42 bytes initially. Running each string through Oc
gives us:
Step 1
##Step 1 But, we can do better. If we join the array to a newline separated string, we can get rid of the brackets, commas, and extraneous backticks and split on newline to get our array. Applying that to our example array gives us the following:
##Step 2
Step 2
##Step 3
Step 3
Bonus Tip: Integer Array Compression
##Bonus Tip: Integer Array Compression YouYou can apply the same principle to arrays of integers by first converting each to a higher base. Using this sample, 36 byte array:
##Notes
Notes
##Credits