Array数组练习

将一串字符串的每个单词首字母转换为大写,其余小写(除a, an, the…)

function Case(arr) {
  const exceptions = ["a", "an", "and", "the", "but", "or", "on", "in", "with"];
  const TitleCase = (str) => str[0].toUpperCase() + str.slice(1);

  const arrNew = arr
    .toLowerCase()
    .split(" ")
    .map((mov) => (exceptions.includes(mov) ? mov : TitleCase(mov)))
    .join(" ");

  return arrNew;
}

console.log(Case("This is A nice tiTle"));		//This Is a Nice Title

组合题(Dog Dog Dog)----------

初始数据

const dogs = [
  { weight: 22, curFood: 300, owners: ["Tom", "Chris"] },
  { weight: 8, curFood: 200, owners: ["Matilda"] },
  { weight: 13, curFood: 255, owners: ["Sarah", "John"] },
  { weight: 32, curFood: 185, owners: ["Michael"] },
];

1. 为数组添加一个属性recFood(recFood = weight ** 0.75 * 28),不进行新数组地创建

recFood : 建议食入量

2. 找到指定人物的所有元素

找到Alice的狗,并log输出狗狗吃的食物是否符合建议克数(recFood > curFood --> too little 否则 too much)

3. 创建新数组

ownersEatTooMuch — 狗狗吃太多食物的主人名
ownersEatTooLittle — 太少的
eg: ownersEatTooMuch = [‘Matilda’, ‘Sarah’, ‘John’]

4. 那些狗狗的食物量合适,并输出

公式 :current > (recommended * 0.90) && current < (recommended * 1.10)

5. 按照recFood排序

在这里插入图片描述

项目LINK :项目链接

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值