We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
这些JavaScript编程黑科技,装逼指南,高逼格代码,让你惊叹不已
包含小数的实现 ★构建东半球最小的评级组件☆
function rate(num){ return "★★★★★☆☆☆☆☆".slice(5 - num, 10 - num); } rate(3) // "★★★☆☆"
跳转到 stackoverflow 网站。
try { something } catch (e) { window.location.href = "http://stackoverflow.com/search?q=[js]+" + e.message; }
将页面所有的元素用不同颜色的1px 的边框包裹。
[从一行代码里面学点 JavaScript] [Learning much javascript from one line of code]
[从一行代码里面学点 JavaScript]
[Learning much javascript from one line of code]
[].forEach.call($$("*"),function(a){ a.style.outline="1px solid #"+(~~(Math.random()*(1<<24))).toString(16) })
翻译成正常语言
Array.prototype.forEach.call(document.querySelectorAll('*'), dom => dom.style.outline = `1px solid #${parseInt(Math.random() * Math.pow(2,24)).toString(16)}`)
Math.random().toString(16).substring(2) Math.random().toString(36).substring(2)
var a = ~~2.33 var b= 2.33 | 0 var c= 2.33 >> 0
var test1 = '1234567890' var format = test1.replace(/\B(?=(\d{3})+(?!\d))/g, ',') console.log(format) // 1,234,567,890
Array(6).fill(8)
var numbers = [5, 458 , 120 , -215 , 228 , 400 , 122205, -85411]; var maxInNumbers = Math.max.apply(Math, numbers); var minInNumbers = Math.min.apply(Math, numbers);
The text was updated successfully, but these errors were encountered:
金钱格式化:1234567890 --> 1,234,567,890; 中的正则 /\B(?=(\d{3})+(?!\d))/g
/\B(?=(\d{3})+(?!\d))/g
?!: 正向否定断言,表示连续三个数字之后不能存在数字。 所以,123456 不满足条件,但是234567满足,因为7之后不存在数字。
?!
?= :
?=
(?=exp)也叫零宽度正预测先行断言,它断言自身出现的位置的后面能匹配表达式exp。
可以理解为?=是一个狂妄的预言家,假设有正则 /abc?=xxx/,它预言自己出现的位置后面一定、肯定、必须、只能是 xxx,如果不是,那它会以死明志的(就是匹配失败)。 所以,?=(\d{3})+(?!\d)匹配三个数字的一组或多组数字 且 不能以数字结尾 的位置。
?=(\d{3})+(?!\d)
replace(/(\d{3})(?=[^$])/g, "$1,")
?:
\B
Regulex regexper
Sorry, something went wrong.
No branches or pull requests
这些JavaScript编程黑科技,装逼指南,高逼格代码,让你惊叹不已
1.Tiny Rate
包含小数的实现 ★构建东半球最小的评级组件☆
2.JavaScript 错误处理的方式的正确姿势
跳转到 stackoverflow 网站。
3.从一行代码里面学点JavaScript
将页面所有的元素用不同颜色的1px 的边框包裹。
翻译成正常语言
4.论如何优雅的取随机字符串
5.论如何优雅的取整
6.如何优雅的实现金钱格式化:1234567890 --> 1,234,567,890
7.用最短的代码实现一个长度为m(6)且值都n(8)的数组
8.取出一个数组中的最大值和最小值
The text was updated successfully, but these errors were encountered: