Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function shortestAndLongestWord(input) {
- let asd = input.replace(/[.,!?-]/g,"");
- let wordsArray = input.split(" ");
- let biggestLength = 0;
- let longestWord = '';
- let smallestLength = Number.MAX_SAFE_INTEGER;
- let shortestWord = '';
- for ( let i = 0; i < wordsArray.length; i ++ ) {
- if ( wordsArray[i].length > biggestLength ) {
- biggestLength = wordsArray[i].length;
- longestWord = wordsArray[i];
- }
- if ( wordsArray[i].length < smallestLength ) {
- smallestLength = wordsArray[i].length;
- shortestWord = wordsArray[i];
- }
- }
- console.log('Longest -> ' + longestWord);
- console.log('Shortest -> ' + shortestWord);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement