Task 1: Find the longest word Implement the function findLongestWord that takes as an argument an array of words and returns the longest one. If there are 2 with the same length, it should return the first occurrence. Write the JS code in a separate file. You can use the following array to test your solution: var words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpott'];
Task 1: Find the longest word
Implement the function findLongestWord that takes as an argument an array of words and returns the longest one. If there are 2 with the same length, it should return the first occurrence. Write the JS code in a separate file.
You can use the following array to test your solution:
var words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpott'];
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images
Task 2:
Implement the function Searchingstrings that allow to search a sub-string in a given string and display the: First occurrence, Last occurrence, First occurrence from a given index and Last occurrence from a given index.
You can use the following String methods:
string. IndexOf(searchvalue, start) return the position of the first occurrence of specified character(s) in a string.
string.lastIndexOf(searchvalue, start) return the position of the last occurrence of specified character(s) in a string.
You can use the following string to test your solution:
var letters = "abcdefghijklmnopqrstuvwxyzabcdefghijklm";
Write the code in a separate.js and separate.html file.