阿里前端 简历测评 三道笔试题
电话简历测评:问了一下react原理,项目难点,我答得不好,面试官直接叫我做笔试题,15min左右。
当时笔试题我只会第一题,第二题有点思路,第三题要用正则不然很麻烦,当时不太会正则,结合刚才表现权衡了一下决定放弃笔试。
下面是我的答案,可能有错误的地方欢迎指出:
//递归实现快排 function quickSort(arr) { let stack = []; stack.push([0, arr.length - 1]); while(stack.length) { let curr =stack.pop(); let left = curr[0]; let right = curr[1]; if(left > right) { continue; } let pivot = arr[left]; let l = left; let r = right; while(l !== r) { while(l < r && arr[r] >= pivot) { r--; } while(l < r && arr[l] <= pivot) { l++; } [arr[l], arr[r]] = [arr[r], arr[l]]; } if(left !== l) { [arr[left], arr[l]] = [arr[l], arr[left]]; } stack.push([l+1, right]); stack.push([left, l-1]); } return arr; } quickSort([34,432,15,32,41,532,1,53,41]); // 100毫秒调度器 function scheduler(fn, ...args) { let timer = null; this.start = () => { timer = setInterval(() => {fn(...args)}, 100); } this.stop = () => clearInterval(timer); } function test(a, b) { console.log((new Date()).getTime(), " ", a + b); } let scheduler_test = new scheduler(test, 1, 2); scheduler_test.start(); setTimeout( () => {scheduler_test.stop()}, 1000); // 判断字符串是不是ip地址或者是人民币格式 function isRMB_or_isIP( str ) { let reg_ipv4 = /^\b((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}(\b$)/; let reg_RMB = /^¥\d{1,3}(,\d{3})*(\.\d{1,2})?(\b$)/; if(reg_ipv4.test(str)) { //console.log(str.match(reg_ipv4)); return "IS_IP" } if(reg_RMB.test(str)) { //console.log(str.match(reg_RMB)); return "IS_RMB" } return "ERROR" } console.log(isRMB_or_isIP("122.111.0.1")) console.log(isRMB_or_isIP("0.0.0.0")) console.log(isRMB_or_isIP("256.0.0.0")) console.log(isRMB_or_isIP("256.0.0.0000")) console.log(isRMB_or_isIP("255.0.0.0")) console.log(isRMB_or_isIP("¥123,456,789.12")) console.log(isRMB_or_isIP("¥124.000"))