Skip to content

Commit 23dcd16

Browse files
committed
first two problems
1 parent 28b0de1 commit 23dcd16

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

solutions/First_Reverse.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*Have the function FirstReverse(str) take the str parameter being passed and return the string in reversed order. For example: if the input string is "Hello World and Coders" then your program should return the string sredoC dna dlroW olleH.
2+
3+
Use the Parameter Testing feature in the box below to test your code with different arguments.
4+
*/
5+
*
6+
function FirstReverse(str) {
7+
var reverse = '';
8+
for(var i = str.length - 1; i >= 0; i--)
9+
reverse += str[i];
10+
return reverse;
11+
return str;
12+
13+
}

solutions/find_Longest_Word.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function LongestWord(sen) {
2+
3+
// First convert the string into an array with only the words.
4+
// Then compare each words.length (after removing special characters from word) and sort these lengths in descending order.
5+
// return the first element from that sorted array.
6+
7+
var sentence = sen.split(" ")
8+
.sort(function(a,b){
9+
return b.replace(/[^a-zA-Z]/g, "").length - a.replace(/[^a-zA-Z]/g, "").length;
10+
});
11+
return sentence.shift();
12+
}

0 commit comments

Comments
 (0)