You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

实现makeStrings函数:生成判断能否观看《黑客帝国》的字符串数组

实现JavaScript的makeStrings函数

需求说明

  • 接收一个包含name(姓名)和age(年龄)属性的对象数组作为参数
  • 返回对应规则的字符串数组:
    • 若对象的age ≥ 18,生成字符串:[姓名] can go to The Matrix
    • 若对象的age < 18,生成字符串:[姓名] is under age!!

修正后的实现代码

function makeStrings(people) {
  return people.map(person => {
    return person.age >= 18 
      ? `${person.name} can go to The Matrix` 
      : `${person.name} is under age!!`;
  });
}

测试验证

测试代码

console.log(makeStrings([
    {name: "Angelina Jolie", age: 80},
    {name: "Eric Jones", age: 2},
    {name: "Paris Hilton", age: 5},
    {name: "Kayne West", age: 16},
    {name: "Bob Ziroll", age: 100}
]));

预期输出

["Angelina Jolie can go to The Matrix", "Eric Jones is under age!!", "Paris Hilton is under age!!", "Kayne West is under age!!", "Bob Ziroll can go to The Matrix"]

内容的提问来源于stack exchange,提问作者GardenDarts

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 16:03:17