我写了一个函数,它接收一个句子并计算该句子中最长的单词.
function findLongestWord(str) {
var charArray = str.split(" ");
var wordArray = [];
for(var i = 0; i < charArray.length; i++ ) {
wordArray.push(charArray[i].length);
wordArray.sort();
wordArray.reverse();
}
return wordArray[0];
}
Run Code Online (Sandbox Code Playgroud)
我的功能适用于以下输入:
findLongestWord("The quick brown fox jumped over the lazy dog");
Run Code Online (Sandbox Code Playgroud)
但是当我通过它时:
findLongestWord("What if we try a super-long word such as otorhinolaryngology")
Run Code Online (Sandbox Code Playgroud)
该函数返回:
4
Run Code Online (Sandbox Code Playgroud)
而不是
19
Run Code Online (Sandbox Code Playgroud) 我编写了一个函数,它接受两个参数:(1)一个数组,(2)块的大小.
function chunkArrayInGroups(arr, size) {
var myArray = [];
for(var i = 0; i < arr.length; i += size) {
myArray.push(arr.slice(i,size));
}
return myArray;
}
Run Code Online (Sandbox Code Playgroud)
我想将这个数组拆分成给定大小的块.
chunkArrayInGroups(["a", "b", "c", "d"], 2)
Run Code Online (Sandbox Code Playgroud)
应该回来:[["a", "b"], ["c", "d"]].
我回来了: [["a", "b"], []]
我想我可以通过使导航栏透明来使我的网站看起来更好,所以你可以看到它下面的图像略微暗淡的版本.我找不到任何告诉我如何做的事情.有人可以帮帮我吗?
@import url(https://fonts.googleapis.com/css?family=Pacifico);
@import url(https://fonts.googleapis.com/css?family=Patua+One);
body {
margin: 0px
}
header {
background: #000;
color: white;
padding: 5px 15px 0px 15px;
}
header h1 {
font-size: 30px;
margin: 0;
display: inline;
padding: 30px;
font-family: 'Pacifico', cursive;
}
nav ul {
margin: 0;
display: inline;
padding: 50px;
}
nav ul li {
background: black;
color: white;
list-style-type: none;
display: inline-block;
padding: 20px 35px;
margin: 0px;
font-family: 'Patua One', cursive;
}
nav ul li:hover {
color: #999;
}
#hero,
#hero1,
#hero2,
#hero3, …Run Code Online (Sandbox Code Playgroud)我正在学习AngularJS,在我接下来的教程中我们不得不使用货币过滤器,我注意到这个变化,例如10,变成10.00美元.
我怎么做英镑?
<p class="price">{{ product.price | currency }}</p>
Run Code Online (Sandbox Code Playgroud) 我想在屏幕上显示一个按钮,旁边是单个字符输入字段.当用户点击按钮时,角色将旋转1度,单击它5次,它将旋转5度,按住它并旋转.
我也希望能够向用户显示当前的旋转度(这对于我想在最后构建的内容非常重要).
目前我有HTML:
<h2 class="rotate10"> P</h2>
Run Code Online (Sandbox Code Playgroud)
CSS:
.rotate10{
/* Safari */
-webkit-transform: rotate(-10deg);
/* Firefox */
-moz-transform: rotate(-10deg);
/* IE */
-ms-transform: rotate(-10deg);
/* Opera */
-o-transform: rotate(-10deg);
/* Internet Explorer */
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
}
Run Code Online (Sandbox Code Playgroud)