直接上题
滴滴
1、对称加密和非对称加密
2、https ssl
3、取消请求
4、防抖 最后一次生效;节流第一次生效
5、浮点数相加实现
6、超出范围 MAX_SAFE_INTERGER MIN_SAFE_INTERGER BigInt
7、状态码
跟谁学
arrayreduce实现
菲波那切数列 递归、非递归实现
小米
浏览器缓存机制、本地存储
有序数组排序
数组去重
节流实现
小米二面
链表数组反转
快手
有序数组排序
布局相关
实现fetch的delay效果
boss直聘
currenttarget和target的区别
抖音
vue的实现
vue-router实现
Array.prototype.my_reduce = function (callback, initialValue) {
if (!Array.isArray(this) || !this.length || typeof callback !== 'function') {
return []
} else {
// 判断是否有初始值
let hasInitialValue = initialValue !== undefined;
let value = hasInitialValue ? initialValue : tihs[0];
for (let index = hasInitialValue ? 0 : 1; index < this.length; index++) {
const element = this[index];
value = callback(value, element, index, this)
}
return value
}
}
let arr = [1, 2, 3, 4, 5]
let res = arr.my_reduce((pre, cur, i, arr) => {
console.log(pre, cur, i, arr)
return pre + cur
}, 10)
console.log(res)//25
let leftArr = new Array(3).fill('(')
let rightArr = new Array(3).fill(')')
let res=''
while(leftArr.length > rightArr.length) {
res+=leftArr.shift
}
getaabb = (n) => {
if(n=1) {
return ['()']
}
let str1 = ''
let str2 = ''
while(n>0) {
str1 += '('
str2 += ')'
}
let arr1 = []
let arr2 = []
for(let i = 0;i {
if (cur.length === 2 * n) {
res.push(cur);
return;
}
if (left < n) {
drow(cur + "(", left + 1, right)
}
if (left > right) {
drow(cur + ")", left, right + 1);
}
};
drow("", 0, 0);
return res;
};
'12123ab234aa234564'最长数字子串
let getNum = (str) => {
let res = ''
for(var i = 0; i < str.length; i ++) {
if((!res.length || (Number(res[res.length - 1]) + 1 == str[i]))) {
res = str.substring(0, i+1)
} else {
str = str.substring(i, str.length)
i=0;
}
console.log(i)
}
console.log(res, 'res')
}
var lengthOfLongestSubstring = function(s) {
var res = 0; // 用于存放当前最长无重复子串的长度
var str = ""; // 用于存放无重复子串
var len = s.length;
for(var i = 0; i < len; i++) {
var char = s.charAt(i);
var index = str.indexOf(char);
if(index === -1) {
str += char;
res = res < str.length ? str.length : res;
} else {
str = str.substr(index + 1) + char;
}
}
return res;
}
//爬楼梯问题
function climbStairs(n) {
if (n === 1 || n === 2) {
return n;
}
var ways = [];
ways[0] = 1;
ways[1] = 2;
for(var i=2; i {
if (n<3) {
return n
}
let a = 1,b=2,res
for(let i = 3; i <= n; i++) {
res = a+b
a=b
b=res
}
return res
return helper(n-1) + helper(n-2)
}
}
// 给定连续正整数数组,抽掉中间一个数字后乱序,求丢掉的数字
[3, 6, 8, 4, 2, 7] -> 5
const getLostNum = (arr) => {
let arrSort = arr.sort((a, b) => {
return a - b
})
let lostNum;
for(let i = 0;i {
for(let i = 0; i {
if(pendingCount <= 3) {
download().then(() => {
pendingCount --
controlThrottle(pendingArr.splice(0,1))
})
} else {
pendingArr.push(event)
}
}
const download = () => {
pendingCount += 1
return new Promise((resolve, reject) => {
resolve()
})
}
el.onclick(controlThrottle());
// 给定一个字符串,找出其中不含重复字符的最长字串的长度
const getSub = (str) => {
let res = '';
let max = 0;
for(let i=0;i -1) {
res = res.substring(res.indexOf(now)+1)+str[i]
} else {
res+=now;
max = math.Max(res.length,max);
}
}
return max
}
// 抖音 add(2,3,4)=9 add(2)(3,4)=9 add(2)(3)(4)=9 add(2,3)(4)=9
let add = function() {
let sum = [...arguments].reduce((prev, next) => { return prev + next})
let tmp = function() {
sum += [...arguments].reduce((prev, next) => { return prev + next})
return tmp
}
tmp.toString = function() {
return sum
}
return tmp
}