作业练习题

1)js异步编程的理解:说到异步,就相应的说下同步的概念,同步就是等待执行,等待当前进程执行完才能向下执行,s异步编程就是不用等待其他进程执行完毕才能继续往下执行,不会造成耗时太长的问题。
2)EventLoop是事件循环机制,是在调用栈和消息队列中调取可执行的程序代码。消息队列表示的是当前有多少个程序代码需要在队列中执行
3)宏任务和微任务,宏任务表示的是不会马上执行结束的程序,例如setTimeout,微任务表示的是马上有执行结果的。
2.代码改进问题
const promise = new Promise((resolve, reject) => {
let a = 'hello ';
resolve(a);
});

promise.then((value) => {
let b = 'lagou ';
return value + b;
}).then(value => {
let c = ‘I Love U’;
console.log(value + c);
});
3.练习题
1)const fp = require(‘lodash/fp’);
const cars = [
{
‘name’: ‘FF’,
horsepower: 660,
dollar_value: 700000,
in_stock: true,
},
{
‘name’: ‘XKR-S’,
horsepower: 550,
dollar_value: 132000,
in_stock: false,
},
{
‘name’: ‘R8’,
horsepower: 525,
dollar_value: 700000,
in_stock: true,
},
{
‘name’: ‘Huayra’,
horsepower: 525,
dollar_value: 700000,
in_stock: true,
},
];
// let last_car = fp.last(cars);
// console.log(fp.prop(‘in_stock’, last_car));
const f = fp.flowRight(fp.prop(‘in_stock’), fp.last);
console.log(f(cars));
2)const f2 = fp.flowRight(fp.prop(‘name’), fp.first);
console.log(f2(cars));
3)let _average = function (xs) {
return fp.reduce(fp.add, 0, xs) / xs.length;
}
let averageDpllarValue = function (cars) {
let dollar_values = fp.map(function (car) {
return car.dollar_value
}, cars);
return _average(dollar_values);
}
// console.log(averageDpllarValue(cars));

const f1 = fp.map(car => {
return car.dollar_value
});
const f2 = fp.flowRight(_average, f1)
console.log(f2(cars));

4)sanitizeNames([‘Hello World’])转成sanitizeNames([‘hello_world’])
let underscore = fp.replace(/\W+/g, '’);
const f1 = function sanitizeNames (name) {
return name;
};

const f2 = fp.flowRight(f1, fp.toLower, _underscore);
console.log(f2([‘Hello World’]));
4.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值