w3resource

CoffeeScript function: Returns a passed string with letters in alphabetical order

CoffeeScript Function : Exercise-11 with Solution

Write a CoffeeScript function that returns a passed string with letters in alphabetical order.

Example string : 'webmaster'
Expected Output : 'abeemrstw'

Note: Assume punctuation and numbers symbols are not included in the passed string.

HTML Code :

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<script src="//jashkenas.github.io/coffee-script/extras/coffee-script.js"></script>
<title>Returns a passed string with letters in alphabetical order</title>
</head>
<body>
  
</body>
</html>

CoffeeScript Code :

alphabet_order = (str) ->
  str.split('').sort().join ''

console.log alphabet_order('webmaster')

Sample Output:

"abeemrstw"

Live Demo :

See the Pen coffeescript-exercise-11 by w3resource (@w3resource) on CodePen.


Improve this sample solution and post your code through Disqus.