code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

04 Largest Number

/**
 * Created by Ashish Patel
 * Copyright © 2017 ashish.me
 * ashishsushilpatel@gmail.com 
 */

/**
 * Program:
 * Return the length of the longest word in the provided sentence.
 * Your response should be a number.
 */

 function getLongestWordLength(str){
    return str.split(' ').reduce((longest, index) =>
         longest.length > index.length ? longest : index
    , 0).length;
 }

 console.log(getLongestWordLength("Lorem ipsum dolor sit amet, consectetur adipiscing elit"));

Created 2019-11-24T04:41:20+05:18 · Edit