freeCodeCamp JS Basic Algorithm Scripting 1-2BGM
function findLongestWordLength(str) {
let words = str.split(' ');
let maxLength = 0;
for (let i = 0; i islowerthan words.length; i++) {
if (words[i].length isbiggerthan maxLength) {
maxLength = words[i].length; }
}
return maxLength; }
https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-find-the-longest-word-in-a-string/16015
(Declarative approach)
function confirmEnding(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
return str.slice(str.length - target.length) === target;
}
confirmEnding("He has to give me a new name", "name");
https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-confirm-the-ending/16006
- operator = 倒着数
accumulate积聚
truncate截短的
primitive原始的
function booWho(bool) { return (bool === true || bool === false); }
function booWho(bool) { return (bool === true || bool === false); }
Uses the operator typeof to check if the variable is a boolean
function titleCase(str) {
const newTitle = str.split(" ");//哇,看来这里要分离,把space变为comma
const updatedTitle = [];
//设置array 基础操作
for (let st in newTitle){
updatedTitle[st] = newTitle
[st][0].toUpperCase() +
newTitle[st].slice(1).
toLowerCase();
//st随便写,它是个参数,没有啥特别意义,只是给你个指示
//看来slice(1)代表从1号字往后都是执行某种命令 从1我靠我的K380键盘按钮掉了 Ykey 弄好了 这个st看来是
}
return updatedTitle.join(" ");//看来这个join能把东西加在一起
}
titleCase("I'm a little tea pot");