Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function longestString(i) {
- // i will be an array.
- // return the longest string in the array
- var itemLength = 0;
- var item;
- for(j = 0; j < i.length; j++) {
- if(typeof(i[j]) !== 'string') {
- i.splice(j, 1);
- } // end typeof
- if(i[j].length > itemLength) {
- itemLength = i[j].length;
- item = i[j];
- }
- }
- //console.log(array);
- return item;
- }
Advertisement
Add Comment
Please, Sign In to add comment