Skip to content

Instantly share code, notes, and snippets.

@mis101247
Last active November 14, 2019 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mis101247/d5f3fb131d1bc0092558b8daa4048430 to your computer and use it in GitHub Desktop.
Save mis101247/d5f3fb131d1bc0092558b8daa4048430 to your computer and use it in GitHub Desktop.
#Medium
// 去識別化
function deIdentification(str) {
const showLen = Math.round(str.length / 2); // 顯示幾個
const markLen = str.length - showLen; // 要隱藏幾個
const showStart = Math.round((str.length - showLen) / 2) ; // 從哪開始隱
return str.replace(str.substr(showStart, markLen), '*'.repeat(markLen));
}

deIdentification('a')

a

deIdentification('ab')

a*

deIdentification('abc')

a*c

deIdentification('abcd')

a**d

deIdentification('abcde')

a**de

deIdentification('abcdef')

ab***f

deIdentification('abcdefg')

ab***fg

deIdentification('abcdefgh')

ab****gh

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