implement btoa()
2022年5月1日小于 1 分钟
implement btoa()
Question
btoa() accepts a binary string and returns a Base64-encoded ASCII string from it. Characters in a binary string are the ASCII character for each byte of the binary data.
Please read Base64 wiki and implement your own btoa()
.
myBtoa('BFE')
// 'QkZF'
myBtoa('BFE.dev')
// 'QkZFLmRldg=='
note
- Please don't use
window.btoa()
in your code. - The binary string passed to your function are all valid ASCII characters, there will be another problem on the general Base64 encoding/decoding.
Code
/**
* @param {string} str - binary string
* @returns {string}
*/
function myBtoa(str) {
// your code here
}