Created
February 20, 2020 14:59
-
-
Save gbutt/f5521c42acc144ce89dc85d7ca2a2197 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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