[JS Practice] Limit string length (one line function)

Title :

Limit string length

Description:

Complete the solution, so that it returns the truncated version of the string followed by ‘…’.

Example:

solution('Testing String',3) // should return 'Tes...'
solution('Testing String',8) // should return 'Testing ...'
solution('Test',8) // should return 'Test'

My solution :

function solution(string,limit){
  return (string.length > limit) ? string.substr(0, limit).concat("...") : string;
}

 

Ref. from codewars

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s