freeCodeCamp:Find the Longest Word in a String
找到提供的句子中最长的单词,并计算它的长度。
函数的返回值应该是一个数字。
1 /* 2 先把字符串 str 转为数组 myarr 3 将数组myarr中的每个元素长度转换成一个新的数组newarr 4 将这个数组按由小到大排序 5 取此数组中最后的数值,也就是最长的字符串 6 将这个长度值返回 7 */ 8 9 function findLongestWord(str) { 10 //把字符串 str 转为数组 myarr 11 var myarr=str.split(" "); 12 //定义longest方便调用 13 var longest=0; 14 //遍历数组myarr,myarr.length=6 15 for(var i=0;i<myarr.length;i++){ 16 //遍历新数组myarr并将数组中最大的值赋值给longest 17 if(myarr[i].length>longest){ 18 longest=myarr[i].length; 19 } 20 } 21 return longest; 22 } 23 24 findLongestWord("The quick brown fox jumped over the lazy dog");
转载于:https://www.cnblogs.com/zhouhelong/p/5909805.html
freeCodeCamp:Find the Longest Word in a String相关推荐
- (Greedy approach)Find longest word in dictionary that is a subsequence of a given string
Find longest word in dictionary that is a subsequence of a given string 贪心算法: 1)将D按字符串的长度,从长到短排序. 2) ...
- LeetCode 524. Longest Word in Dictionary through Deleting
题目: Given a string and a string dictionary, find the longest string in the dictionary that can be fo ...
- C#LeetCode刷题之#720-词典中最长的单词(Longest Word in Dictionary)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4120 访问. 给出一个字符串数组words组成的一本英语词典.从 ...
- leetcode 720. Longest Word in Dictionary | 720. 词典中最长的单词(Trie前缀树)
题目 https://leetcode.com/problems/longest-word-in-dictionary/ 题解 建立一个 Trie,在 insert 的过程中,除最后一个节点外,如果一 ...
- freeCodeCamp算法
/* Reverse a String 翻转字符串 先把字符串转化成数组,再借助数组的reverse方法翻转数组顺序,最后把数组转化成字符串. 你的结果必须得是一个字符串 */ function re ...
- Freecodecamp 刷题记录——前端基础算法
Basic Front End Development Projects Reverse a String 翻转字符串 先把字符串转化成数组,再借助数组的reverse方法翻转数组顺序,最后把数组转化 ...
- 在JavaScript中重复字符串的三种方法
In this article, I'll explain how to solve freeCodeCamp's "Repeat a string repeat a string" ...
- 在JavaScript中反转字符串的三种方法
This article is based on Free Code Camp Basic Algorithm Scripting "Reverse a String" 本文基于F ...
- android 字符串数组去重,GitHub - deng-ming-hao/ec-do: 实例为日常开发常用的小实例,包括数组去重,打乱数组,字母大小写转换,cookie操作的封装等。...
ec-do 自己封装的常用操作实例 实例为日常开发常用的小实例,包括数组去重,打乱数组,字母大小写转换,cookie操作的封装等. 使用方法 引入ec-do.js //去除空格 ecDo.trim(' ...
最新文章
- spring cloud config将配置存储在数据库中
- 前戴尔EMC中国研究院院长创业:推出AI加速虚拟化平台,开发者可免费使用
- 简单好用的PHP无限分类
- ❤️六W字《计算机基础知识》(二)(建议收藏)❤️
- 读取properties文件,中文乱码
- Node.js和io.js将合并到Node基金会下
- Centos7+LVS-DR+Apache负载均衡web实验
- python 删除字典数据,Python简单遍历字典及删除元素的方法
- 自动化生产线仿真教学
- 通过蚁剑,利用eval与assert,登录目标网站
- SudaMod-81.0 / crDroidAndroid-8.1(android-8.1.0_r20)红米3 2018年5月3日更新
- 市场监管新规下Android接入的友盟Umeng移动统计/推送/分享SDK过程问题总结
- sniper安装配置
- Java的发展前景与就业趋势如何?
- Polkit (简体中文)
- java的抽象类的三角形周长_怎么使用Java把抽象类改为接口计算三角形,长方形,圆形的面积?...
- 激活office 2010
- tp6验证码点击刷新
- 发酵罐中德国贝朗、瑞士比欧、美国NBS的比较
- php使用递归完成以下图形,php试题与答案(一)
热门文章
- Java 折半查询_java之折半查询
- java并发实战看不懂,附带学习经验
- 【Deep Learning笔记】语义分割网络-Segnet的探索
- Keras【Deep Learning With Python】keras框架下的MNIST数据集训练及自己手写数字照片的识别(分类神经网络)
- Python程序设计题解【蓝桥杯官网题库】 DAY6-基础练习
- 使用keras时下载VGG19过慢的解决方法
- java 动态增加控件_在ngIf中动态添加组件
- idea在mac版怎么配置svn_使用Mac自带svn搭建服务器,并使用idea进行连接
- LINUX不能ping域名, 能ping ip, 添加DNS解析
- 搜索引擎是如何判断网站质量的?