Skip to content

Instantly share code, notes, and snippets.

@areagray
Created January 14, 2014 04:25
Show Gist options
  • Save areagray/8413018 to your computer and use it in GitHub Desktop.
Save areagray/8413018 to your computer and use it in GitHub Desktop.
Coderbyte: Using the JavaScript language, have the function DivisionStringified(num1,num2) take both parameters being passed, divide num1 by num2, and return the result as a string with properly formatted commas. If an answer is only 3 digits long, return the number with no commas (ie. 2 / 3 should output "1"). For example: if num1 is 123456789 …
//Coderbyte DivisionStringified
function DivisionStringified(num1,num2) {
//divide, round, convert
var result = x = Math.round(num1/num2).toString();
var groups =[];
//section out 3 digits at a time from end
while (result.length>3){
pusher=result.slice(result.length-3,result.length);
groups.push(pusher);
result= result.slice(0, hey.length-3);
}
//final section goes to array
groups.push(result);
//reverse, join and wammo
return groups.reverse().join();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment