JavaScript的Date对象有容错性,可将随意给定的日期的年月日自动生成正确的日期时间 //JavaScript中Date对象容错性 function dateCheck(){ var date = new Date(); date.setDate(date.getDate()+13); //date.setDate(date.getMonth()+1+10); //打印依然能输出正确的日期 console.log(date.getFullYear()+"年"+(date.get…
题目链接 : https://leetcode.com/problems/generate-parentheses/?tab=Description 给一个整数n,找到所有合法的 () pairs For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())", "()()()" ] 递归程…
已知一个字符串#####,现需要替换偶数位置的#为&. function replaceDemo(){ var s = "1#2#3#4#5#"; var regex = /#/g; var index = 1; s=s.replace(regex,function(){index++;return index%2?'&':arguments[0]}); return s; } 注释: 1.由于需要匹配整个字符串,因此政策表达式需要添加g参数. 2.index用于记录匹…