Skip to content

Instantly share code, notes, and snippets.

@gbutt
Created February 20, 2020 14:59
Show Gist options
  • Save gbutt/f5521c42acc144ce89dc85d7ca2a2197 to your computer and use it in GitHub Desktop.
Save gbutt/f5521c42acc144ce89dc85d7ca2a2197 to your computer and use it in GitHub Desktop.
var ascii_image = `
############ ########
################## ##############
###################### ##################
###########################################
#############################################
###############################################
##################################################
##################~ #############################
########################## ###############################
########################### #####################################
############################ #######################################
################ ### #### ## ##############
################ ## ### ### ~#############
############### ########### ,### ##. #### =### #############
################ ######## ##### # #### =### ##############
################# .#### ##### ###### =### ##############
#################### .### ##### # ###### =### ##############
####################### ## ##### ## ########### ##############
############### ###+ ### ####. #### ### ##############
############### #### #### ##### ## ##############
################ ~###### ### ###### ## :#################
######################### ###########################################
###################### ##########################################
################# #########################################
######## ##########################################
####################################################
############################################
##########################################
########################################
##################### ##############
################### ######
################
##########
`;
var compressed_image = ascii_image.split('').reduce((acc, curr) => {
if (!acc) { return [curr, 1]; }
acc.slice(-2)[0] === curr ? acc[acc.length-1]++ : acc.push(curr, 1);
return acc;
}, false);
console.log(
compressed_image
.map((i,idx,arr) => idx % 2 === 0 ? i.repeat(arr[idx+1]) : "")
.join("")
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment