constlengthOfLastWord=s=>(s)?s.match(/^.*\b(\w+)/)[1].length:0console.log(lengthOfLastWord('the last word '))//->4console.log(lengthOfLastWord(''))//->0console.log(lengthOfLastWord())//->0constlengthOfLastWord1=function(s){s=s.trim().split('');returns[s.length-1].trim().length;};console.log(lengthOfLastWord1('the last word '))//->4console.log(lengthOfLastWord1(''))//->0console.log(lengthOfLastWord1())//->TypeErrorconstlengthOfLastWord2=function(s){s=s.trim().split('');return(s[s.length-1].length);};console.log(lengthOfLastWord2('the last word '))//->4console.log(lengthOfLastWord2(''))//->0console.log(lengthOfLastWord2())//->TypeError
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Discussion on: code every with me
For further actions, you may consider blocking this person and/or reporting abuse