Skip to content

Commit 8eb27c8

Browse files
committed
Create Division Stringified
1 parent 108f345 commit 8eb27c8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Division Stringified

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/***************************************************************************************
2+
* *
3+
* CODERBYTE BEGINNER CHALLENGE *
4+
* *
5+
* Division Stringified *
6+
* Using the JavaScript language, have the function DivisionStringified(num1,num2) *
7+
* take both parameters being passed, divide num1 by num2, and return the result as *
8+
* a string with properly formatted commas. If an answer is only 3 digits long, *
9+
* return the number with no commas (ie. 2 / 3 should output "1"). For example: *
10+
* if num1 is 123456789 and num2 is 10000 the output should be "12,345". *
11+
* *
12+
* SOLUTION *
13+
* The first step is to divide the two number and get a whole number that you can *
14+
* format according to the directions. I use RegExp to format the number. *
15+
* *
16+
* Steps for solution *
17+
* 1) Divide num1 by num2 and round to whole number *
18+
* 2) Use RegExp to format string as required *
19+
* *
20+
***************************************************************************************/
21+
function DivisionStringified(num1,num2) {
22+
23+
var tot = Math.round(num1 / num2);
24+
var newNum = tot.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
25+
26+
return newNum;
27+
28+
}

0 commit comments

Comments
 (0)