Modify the function to return the longest string in the given array.
function getLongestString(strings) {
}
/* Do not modify code below this line */
const strings = ['long', 'longer', 'longest'];
console.log(getLongestString(strings), '<-- should be
"longest"');
function getLongestString(strings)
{
var i;
var len=strings[0].length;
var index=0
for (i = 1; i < strings.length; i++)
{
if(len<strings[i].length)
{
index=i;
len=strings[i].length;
}
}
return strings[index]
}
/* Do not modify code below this line */
const strings = ['long', 'longer', 'longest'];
console.log(getLongestString(strings), '<-- should be "longest"');
output
If you have any query
regarding the code please ask me in the comment i am here for help
you. Please do not direct thumbs down just ask if you have any
query. And if you like my work then please appreciates with up
vote. Thank You.
Modify the function to return the longest string in the given array. function getLongestString(strings) { }...