0

Alert specified strings?

i need this code to alert the strings that end with the arg "Letter" function HasFinalLetter(strList, Letter) { var arr = []; var str = strList.split(" "); arr.push(str); } HasFinalLetter("Hello World!", "!"); This should only alert "World! The letter can be multiple letters so we can make Letter "llo" And that should alert "Hello" I hope I worded this right

30th Sep 2018, 10:10 PM
Daniel Cooper
Daniel Cooper - avatar
4 Respuestas
+ 1
No need to code anything, javascript has that! "Hello, world!".endsWith("world!"); //true
1st Oct 2018, 12:52 AM
Schindlabua
Schindlabua - avatar
+ 1
Single match method function hasFinalLetter(str, letter) { var re = new RegExp("[ ](\\w+?" + letter + ")|(^\\w+?" + letter + ")"); return str.match(re)[0]; } https://code.sololearn.com/W6QIk5nJKxSg/?ref=app
1st Oct 2018, 3:35 AM
Calviղ
Calviղ - avatar
0
I know this was for a specific assignment somebody posted on brainly Schindlabua lol the function must be called "HasFirstLetter" It must have 2 args. "strList" and "letter" the function must output any words that end with the specified letter/letters
1st Oct 2018, 1:54 AM
Daniel Cooper
Daniel Cooper - avatar
0
It could be a single letter I don't remember
1st Oct 2018, 1:55 AM
Daniel Cooper
Daniel Cooper - avatar