基础题:
1. 实现下面这个方法:
将一维数组切分成二维数组: 按照第二个参数(数字)的值,来决定二维数组长度
let a = ['a', 'b', 'c', 'd'];
// let result = chunk(a, 3);
// console.log(result) => [['a','b', 'c'], ['b']];
// let result = chunk(a, 2);
// console.log(result) => [['a','b'], ['c','b']];
// let result = chunk(a, 1);
// console.log(result) => [['a‘],['b‘],['c‘],['d']];
function chunk(arr, len) {
let res = [];
for (let i=0; i
for (let j=i; j if (j >= arr.length) continue;
tmp.push(arr[j]);
}
res.push(tmp);
}
console.log(res);
return res;
}
2.从某数据库接⼝口得到如下值:
{
rows: [
["Lisa", 16, "Female", "2000-12-01"],
["Bob", 22, "Male", "1996-01-21"] ],
metaData: [ { name: "name", note: '' }, { name: "age", note: '' }, { name: "gender", note: '' }, { name: "birthday", note: '' }
] }
rows 是数据, metaData 是对数据的说明。现写⼀一个函数 parseData ,将上⾯面的对象转化为期 望的数组:
[ { name: "Lisa", age: 16, gender: "Female", birthday: "2000-12-01" }, { name: "Bob", age: 22, gender: "Male", birthday: "1996-01-21" },
]
完成⼀一个函数实现以上功能
const parseData = (data) => {
let res = [];
for (let i in data.rows) {
let obj = {};
let row = data.rows[i];
for (let j in data.metaData) {
obj[data.metaData[j].name] = row[j];
}
res.push(obj);
}
console.log(res);
return res;
}
3、按照调用实例,实现下面的Person方法:
Person("Li");
// 输出: Hi! This is Li!
Person("Dan").sleep(10).eat("dinner");
// 输出:
// Hi! This is Dan!
// 等待10秒..
// Wake up after 10
// Eat dinner~
Person("Jerry").eat("dinner").eat("supper");
// 输出:
// Hi This is Jerry!
// Eat dinner~
// Eat supper~
Person("Smith").sleepFirst(5).eat("supper");
// 输出:
// 等待5秒
// Wake up after 5
// Hi This is Smith!
// Eat supper
function Person(name){
let _person = {
sayHi : function () {
queue.push(() => {
console.log('Hi! This is ' + name + '!');
this.next();
})
},
eat : function (meal) {
queue.push(() => {
console.log('Eat ' + meal + '~');
this.next();
})
return this;
},
sleep : function (second) {
queue.push(() => {
console.log("等待" + second + "秒");
setTimeout(() => {
console.log("wake up after "+ second);
this.next();
}, second * 1000)
})
return this;
},
sleepFirst : function (second) {
queue.unshift(() => {
console.log("等待" + second + "秒");
setTimeout(() => {
console.log("wake up after " + second);
this.next();
}, second * 1000)
})
return this;
},
next : function () {
let fn = queue.shift();
fn && fn();
}
}
let queue = [];
_person.sayHi();
setTimeout(function () {
_person.next();
})
return _person;
}
发散题:
1. 遇到过哪些技术难题?如何解决的?
2. 平时的一些学习方法?以及如何平衡工作和学习上的关系?目前关注哪些技术方向(技术栈)