摘要:并看不懂我不會到處亂說。好吧我努力拆解一下這個正則是什么意思匹配字符串的開始重復一次或更多次匹配除了以外的任意字符原文
problem:
You will create a program that will find the missing letter from a string and return it. If there is no missing letter, the program should return undefined. There is currently no test case for the string missing more than one letter, but if there was one, recursion would be used. Also, the letters are always provided in order so there is no need to sort them.
fearNotLetter("abce") should return "d".
fearNotLetter("abcdefghjklmno") should return "i".
fearNotLetter("bcd") should return undefined.
fearNotLetter("yz") should return undefined.
var arr = []; var all; for (var i=0; i發現和上次一樣,我在進入循環什么時候return出來這里總是做錯,或者想的復雜... 總結一下:return之后會直接結束function;如果for循環一變不出return直接外面來return undefined也是可以的。 basic solution: function fearNotLetter(str) { for(var i = 0; i < str.length; i++) { var code = str.charCodeAt(i); if (code !== str.charCodeAt(0) + i) { return String.fromCharCode(code - 1); } } return undefined; }Intermediate Code Solution:function fearNotLetter(str) { var compare = str.charCodeAt(0), missing; str.split("").map(function(letter,index) { if (str.charCodeAt(index) == compare) { ++compare; } else { missing = String.fromCharCode(compare); } }); return missing; }Advanced Code Solution:function fearNotLetter(str) { var allChars = ""; var notChars = new RegExp("[^"+str+"]","g"); for (var i = 0; allChars[allChars.length-1] !== str[str.length-1] ; i++) allChars += String.fromCharCode(str[0].charCodeAt(0) + i); return allChars.match(notChars) ? allChars.match(notChars).join("") : undefined; }并看不懂我不會到處亂說。好吧我努力拆解一下這個正則是什么意思...
^ 匹配字符串的開始 + 重復一次或更多次 [^x] 匹配除了x以外的任意字符a regular expression notChars which selects everything except str
?: Conditional(ternary)Operatorhttps://developer.mozilla.org...
Syntax:condition ? expr1 : expr2Parameters:
condition (or conditions) An expression that evaluates to true or false.
expr1, expr2 Expressions with values of any type.原文:https://forum.freecodecamp.or...
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/84102.html
Problem Explanation: You will get a DNA strand sequence and you need to get the pair and return it as a 2D array of the base pairs. Keep in mind that the provided strand should be first always. pairEl...
摘要:更多的小算法練習,可以查看我的文章。規則使用語言,使用函數獲取傳遞的參數并使用以下算法對其進行修改。將字符串中的每個字母替換為字母表后面的字母即變為,變為。然后將這個新字符串,,,,中的每個元音大寫,并最終返回此修改后的字符串。 雖然都是很簡單的算法,每個都只需5分鐘左右,但寫起來總會遇到不同的小問題,希望大家能跟我一起每天進步一點點。更多的小算法練習,可以查看我的文章。 規則 Usi...
摘要:我也覺得非常帶勁兒,蛋是,我今天相信的才是正確答案,爾切,可以在又賤又容易的網絡中使用。工具管理這樣的事情在一個中和能夠發現,爾切互相可以交談。這包括了,一個目錄這個目錄中的注冊,爾切,能夠查和到目錄中的。因為,基于一個簡單的,整體簡化了。 糙譯,[Warning] 繼續閱讀可能會感到不適 人一生不可能踩到同一灘大便,故而,本文會持續修改。 Understanding Moder...
摘要: Caching Libraries for caching data. Beaker - A library for caching and sessions for use with web applications and stand-alone Python scripts and applications. dogpile.cache - dogpile.cache...
閱讀 2895·2021-11-24 09:39
閱讀 1157·2021-11-02 14:38
閱讀 4141·2021-09-10 11:26
閱讀 2743·2021-08-25 09:40
閱讀 2303·2019-08-30 15:54
閱讀 477·2019-08-30 10:56
閱讀 2738·2019-08-26 12:14
閱讀 3211·2019-08-26 12:13