Last active
May 14, 2019 08:20
-
-
Save micheleriva/86eda997e424e1a5a306d1f93401c099 to your computer and use it in GitHub Desktop.
This file contains 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
const encode = d => { | |
const encoded = []; | |
d.split('').map(c => { | |
encoded.push((c.charCodeAt(0) / 255)) | |
}) | |
return encoded | |
} | |
const encodeData = data => data.map( d => encode(d) ) | |
encodeData("I am happy"); | |
/* | |
Outputs: | |
[ 0.28627450980392155, | |
0.12549019607843137, | |
0.3803921568627451, | |
0.42745098039215684, | |
0.12549019607843137, | |
0.40784313725490196, | |
0.3803921568627451, | |
0.4392156862745098, | |
0.4392156862745098, | |
0.4745098039215686 ] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is not working.
encodeData
is taking an array not string. In line 11 should beencode("I am happy")