腾娱
最后更新于
这有帮助吗?
😀 腾娱面试总结
navigator.sendBeacon
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bug排查练习</title>
</head>
<body>
<div id="app">
<h1>{{ message }}</h1>
<button @click="changeMessage">Change Message<tton>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script>
new Vue({
el: '#app',
data() {
return {
message: 'Hello World'
};
},
methods: {
changeMessage() {
const promise = new Promise(function(resolve, reject) {
setTimeout(function() {
resolve('New Message');
}, 1000);
});
promise.then(function(newMessage) {
this.message = newMessage;
});
}
}
});
</script>
</body>
<html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>indexOf</title>
</head>
<body>
<script>
String.prototype.indexOf = function(searchString,position){
// 完成该函数的实现
return -1;
}
const paragraph = "I think Ruth's dog is cuter than your dog!";
const searchTerm = 'dog';
const indexOfFirst = paragraph.indexOf(searchTerm);
console.log(`The index of the first "${searchTerm}" is ${indexOfFirst}`);
// Expected output: "The index of the first "dog" is 15"
console.log(
`The index of the second "${searchTerm}" is ${paragraph.indexOf(
searchTerm,
indexOfFirst + 1,
)}`,
);
</script>
</body>
<html>
笔试题
输入:“10 + 2 * 30 - 0.5” 输出:69.5
const suanshu = (flag, index, result, num) => {
const pre = num[index] === null ? result : +num[index]
const next = num[index + 1] === null ? result : +num[index + 1]
switch (flag) {
case '+': return pre + next;
case '-': return pre - next;
case '*': return pre * next;
case '/': if (next === 0) throw new Error('除数不能为0');
return pre / next;
default: return 0;
}
}
const caculate = (str) => {
const flag = []
const num = []
let str1 = ""
const reg = ["*", "+", "-", "/"]
const precedence = { '+': 1, '-': 1, '*': 2, '/': 2 };
for (let i in str) {
const f = reg.findIndex(item => item === str[i])
if (f !== -1) {
flag.push(str[i])
num.push(str1.trim())
str1 = ""
} else {
str1 += str[i]
if (i == str.length - 1) {
num.push(str1.trim())
}
}
}
const flagSortArr = flag.map((item, index) => ({
name: item,
sortIndex: index
})
).sort((a, b) =>
precedence[b.name] - precedence[a.name]
)
let result = 0
const clear = (index1) => {
flag[index1] = null
num[index1] = null
num[index1 + 1] = null
}
for (flagItem of flagSortArr) {
result = suanshu(flagItem.name, flagItem.sortIndex, result, num)
clear(flagItem.sortIndex)
}
return result
}
const teststr = "10 - 20 * 30 / 10 +10"
console.log(caculate(teststr))//-40
笔试题 写的有点差劲了
笔试题相对以前 脑子很慢 还是转了一点 还是有所进步的