【发布时间】:2021-07-05 12:13:00
【问题描述】:
我正在用 JavaScript 进行测试。我被要求执行以下操作:
function IsOffline (users, name) {
// The function called "IsOffline" receives as an argument an array of objects called 'users' and a string called 'name'.
// each object has a property 'name' which is a string and another called 'online' which is a boolean.
// The function must return true if the user is offline, otherwise false.
// ex:
// var users = [
// {
// name: 'toni',
// online: true
//},
// {
// name: 'emi',
// online: true
//},
// {
// name: 'john',
// online: false
//}
//];
//
// IsOffline (users, 'emi') return false
// Your code here:
我有点迷茫,不知道如何开始。感谢您的帮助。
【问题讨论】:
-
您必须查看
users数组以找到其name属性等于name参数的项目并返回该项目的online属性的相反值。提示:你可能想看看Array.prototype.find()(see on MDN) -
为了将来参考,您可能还想看看How do I ask and answer homework questions?
标签: javascript arrays testing boolean javascript-objects