将一串字符串的每个单词首字母转换为大写,其余小写(除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 :项目链接