alankis

JavaScritp under pressure - test 4

Oct 8th, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function longestString(i) {
  2.    
  3.     // i will be an array.
  4.     // return the longest string in the array
  5.    
  6.     var itemLength = 0;
  7. var item;
  8.     for(j = 0; j < i.length; j++) {
  9.         if(typeof(i[j]) !== 'string') {
  10.             i.splice(j, 1);
  11.         } // end typeof
  12.        if(i[j].length > itemLength) {
  13.             itemLength = i[j].length;
  14.             item = i[j];
  15.        }    
  16.    
  17.     }
  18.     //console.log(array);
  19.     return item;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment