+ 15

🔢💻 Challenge: Putting commas! 💻🔢

Write a program that gets a number from user, and prints the number with commas inserted in the correct position. For example: * 123 --> 123 * 1234 --> 1,234 * 98765 --> 98,765 * 1223334444 --> 1,223,334,444 Bonus: Get your program to handle correctly negative numbers. All languages and paradigms are very welcome! One liners, two-liners, tri-liners, tetra-liners, poli-liners, multi-liners, hyper-liners, time-liners, etc, all welcome! Be creative, and most of all: Have fun!! Thanks for your attention.

11th Oct 2017, 11:09 AM
noobcøder
noobcøder - avatar
18 Antworten
11th Oct 2017, 11:12 AM
qwerty
qwerty - avatar
+ 8
https://code.sololearn.com/cfomdHt1yWua/?ref=app
11th Oct 2017, 1:38 PM
Ekansh
11th Oct 2017, 11:25 AM
Kartikey Sahu
Kartikey Sahu - avatar
11th Oct 2017, 11:47 AM
LukArToDo
LukArToDo - avatar
+ 7
@ʎʇɹǝʍb But your link to a C# program. 😂
11th Oct 2017, 3:18 PM
Zephyr Koo
Zephyr Koo - avatar
+ 7
Here's my C# implementation! ✌ Non-LINQ One-Liner〰 new List<int> { 123, -123, 1234, -1234, 98765, -98765, 1223334444 }.ForEach(n => Console.Write(n.ToString("n0"))); It's a trivial challenge for C#. Enjoy~ ❤ https://code.sololearn.com/cpZcRsQX4Bmk/?ref=app
11th Oct 2017, 3:22 PM
Zephyr Koo
Zephyr Koo - avatar
+ 5
@qwerty: Wow! that was fast! 😊
11th Oct 2017, 11:14 AM
noobcøder
noobcøder - avatar
11th Oct 2017, 11:26 AM
林偉雄
林偉雄 - avatar
+ 5
Number.prototype.commas = function (){ return this.toString().split('').map(function(n,i,a) { return (a[0]=='-'&&i==1)||(i==0)||(a.length-i)%3!=0? n:','+n; }).join(''); } https://code.sololearn.com/WG3v612Z4gKl/?ref=app
11th Oct 2017, 11:46 AM
Calviղ
Calviղ - avatar
+ 4
Here you go. Checks for valid input https://code.sololearn.com/cCYpRcd5E2IT/?ref=app
12th Oct 2017, 8:58 AM
Vari93
Vari93 - avatar
+ 3
https://code.sololearn.com/cY7cIYWwteKj/?ref=app
11th Oct 2017, 1:56 PM
Rishita
Rishita - avatar
28th Oct 2017, 2:03 AM
Narasimha
12th Oct 2017, 4:37 PM
Леон Алексанянц
Леон Алексанянц - avatar
+ 2
Here is my answer. I know my code would be better if I could use regexp efficientlly... https://code.sololearn.com/c1K4lJApSdSD/?ref=app
12th Oct 2017, 11:58 PM
Hiroki Masuda
Hiroki Masuda - avatar
+ 2
Here is my code. Can handle leading zeros. https://code.sololearn.com/WT9WBqm7EhED/?ref=app
13th Oct 2017, 7:55 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
14th Oct 2017, 8:05 AM
ⵢⴷⵢⴷ
ⵢⴷⵢⴷ - avatar