Skip to content

Instantly share code, notes, and snippets.

View btk5h's full-sized avatar
🦑

Bryan Terce btk5h

🦑
View GitHub Profile
@btk5h
btk5h / encodeIntArray.js
Last active December 17, 2017 19:46
Compactly represent an array of integers as a string using the base64 alphabet. 40% to 50% smaller output than JSON.stringify.
const TABLE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('')
function encodeInt (int) {
let encoded = ''
do {
let offset = int & 0b011111
int >>>= 5
if (int === 0) {
offset |= 0b100000
}