某面试题
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> </body> </html> <script> /* cookie字符串转对象 输入‘foo=bar;equation=E%3Dmc%5E2’ */ const parseCookie = (str = '') => { return str.split(';')?.reduce((a, b) => { let key = /\w+(?=\=)/.exec(b) let val = /(?<=\=)[\w%]+/.exec(b)[0] let obj = { [key]: unescape(val) } return { ...a, ...obj } }, {}) } // console.log(parseCookie('foo=bar;equation=E%3Dmc%5E2')) /* 找出对象中符合的项 输入{a:1,b:'2',c:3} 条件item=>typeof x ==='string' 输入{b:'2'} */ const pickBy = (obj, fn) => { let _obj = {}; for (let i in obj) { fn(obj[i]) && (_obj[i] = obj[i]) } return _obj } pickBy({ a: 1, b: '2', c: '3' }, item => typeof item === 'string') /* 手机号加密 输入 15806516662,“*”,3,4 从第三位开始的后四位替换成* 输出158****6662 */ const secretMobile = (phone = '', bol = "*", strNum = 3, size = 4) => { let _phone = phone + '' return _phone.replace(new RegExp(`(?<=.{${strNum}})[0-9]{${size}}`), (match) => { let i='' while (size--) { i += bol } return i }) } let a = secretMobile(15806516662, '*', 3,4) console.log(a) </script>
1、路在何方?
路在脚下
2、何去何从?
每个人都在探索,未来的方向在何处。如果说某些方向是世人已经公认的,那么就先按照公认的去走吧(ps:站在巨人的肩膀上看世界会清晰)。
如果说方向,当今世人还不清晰准确。那么就大胆往前走吧,对与错并不重要。心中的方向更加重要。