JavaScript
const code = s => [...s].reduce((a, v) => v.match(/[a-z]{1}/i) ? a+(v.toLowerCase().charCodeAt(0)-96)+' ' : a , '') .trim();
And as an extra, the decoder:
const decode = s => String.fromCharCode(...s.split(' ').map(val=>parseInt(val) + 96));
Although the decoding process is not perfect, because all the spaces and symbols are lost during the coding process. For example, the sentence "The sunset sets at twelve o' clock" will be coded into:
"20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11"
Which will be decoded into:
"thesunsetsetsattwelveoclock"
Link to live demo.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
JavaScript
And as an extra, the decoder:
Although the decoding process is not perfect, because all the spaces and symbols are lost during the coding process. For example, the sentence "The sunset sets at twelve o' clock" will be coded into:
Which will be decoded into:
Link to live demo.