Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用正则实现trim()函数 #20

Open
xxxgitone opened this issue Sep 10, 2017 · 0 comments
Open

使用正则实现trim()函数 #20

xxxgitone opened this issue Sep 10, 2017 · 0 comments

Comments

@xxxgitone
Copy link
Owner

function trim(str) {
   return str.replace(/^\s+/, '').replace(/\s+$/, '')
}
const str = ' string name '
trim(str)  // "string name"

正则表达式这块不怎么熟悉,后面要抽时间再重点学习一下

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

No branches or pull requests

1 participant