A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3resource.com/coffeescript-exercises/coffeescript-exercise-9.php below:

Website Navigation


CoffeeScript function: Reverses a number

CoffeeScript function: Reverses a numberLast update on August 19 2022 21:51:24 (UTC/GMT +8 hours) CoffeeScript Function : Exercise-9 with Solution

Write a CoffeeScript function that reverses a number.

Example x = 58973;
Expected Output : 37985

HTML Code :

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<script src="//jashkenas.github.io/coffee-script/extras/coffee-script.js"></script>
<title>Reverses a number</title>
</head>
<body>
  
</body>
</html>

CoffeeScript Code :

reverse_a_number = (n) ->
  n = n + ''
  n.split('').reverse().join ''

console.log reverse_a_number(58973)

Sample Output:

"37985"

Live Demo :

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

Improve this sample solution and post your code through Disqus.




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4