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
`
var num = 123456789; function format(num) { var str = num.toString().split('').reverse().join(''); str = str.replace(/\d{3}(?!$)/g,"$&,"); return str.split('').reverse().join(''); } //console.log(format(num)) function format1(num) { var str = num.toString(); return str.replace(/\d(?=(\d{3})+$)/g,"$&,") } console.log(format(num)) var str = '1232311a' var reg = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,}/g; var rs = reg.test(str); /* 洗牌算法,核心按序遍历数组, 规则:遍历数组时随机选中一个需要交换的位置两两交换直到遍历结束 */ var arr = [1, 2, 6, 4,8, 6]; function rondomArr(arr) { var len = arr.length; var clone = arr.slice(0); for (var i = 0; i < len; i++) { var index = Math.floor(Math.random()*len); var temp = clone[index]; clone[index] = clone[i]; clone[i] = temp; console.log(clone) } return clone; } /* 每次根据数组的长度随机生成数组的下标, 通过下标选中要插入结果的项 每次插入完之后删除原先数组中的项, 如此循环 */ function rondomArr1(arr) { var clone = arr.slice(0); var result = []; var index; while(clone.length > 0) { index = Math.floor(Math.random() * clone.length); result.push(clone[index]); clone.splice(index, 1) } return result; } /* 找到最大值和最小值,这个需求可以把它当做给数组进行排序 冒泡排序法 */ function findMaxAndMin(arr) { var len = arr.length; var clone = arr.slice(0); var tmp; for (var i = 0; i < len; i++) { for (var j = 0; j < len-i-1; j++) { if (clone[j] > clone[j+1]) { tmp = clone[j]; clone[j] = clone[j+1]; clone[j+1] = tmp; } } } return { max: clone[len - 1], min: clone[0] }; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
`
`
The text was updated successfully, but these errors were encountered: