Skip to content

Instantly share code, notes, and snippets.

@micheleriva
Last active May 14, 2019 08:20
Show Gist options
  • Save micheleriva/86eda997e424e1a5a306d1f93401c099 to your computer and use it in GitHub Desktop.
Save micheleriva/86eda997e424e1a5a306d1f93401c099 to your computer and use it in GitHub Desktop.
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 ]
*/
@fones
Copy link

fones commented May 14, 2019

This is not working. encodeData is taking an array not string. In line 11 should be encode("I am happy")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment