饿了么暑期笔试
选择题
js
var name = 117;
const obj = {
name: "John",
func: function () {
console.log(this.name);
},
};
(obj.name === "John" ? obj.func : "")();
txt
document.body.style.["background-color"] = '#fff';
document.body.style.setProperty('background-color', '#fff');
document.body.style = 'background-color': '#fff';
document.body.style.fontSize = '30px'
js
var name = "tom";
function getMethod() {
var result = () => name;
var name = "Jerry";
return result;
}
var getName = getMethod();
var name1 = getName();
console.log(name1);
编程题
js
function getSum(str) {
let result = "";
for (const s of str) {
if (/[a-z]$/.test(s)) {
result += s.toUpperCase();
} else {
result += s.toLowerCase();
}
}
return result
.split("")
.reduce(
(acc, cur, index) => (index % 2 === 0 ? acc + cur.charCodeAt() : acc),
0,
);
}
console.log(getSum("HeLlo"));