File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments