Skip to content

Instantly share code, notes, and snippets.

View areagray's full-sized avatar

Christopher Gray areagray

View GitHub Profile
@areagray
areagray / letterCountI
Created January 13, 2014 05:44
Coderbyte Challenge.
//Coderbyte Challange.
function LetterCountI(str) {
var words = str.split(' '),
champWord='',
champTotal=0,
champLetter='',
@areagray
areagray / secondGreatLow.js
Created January 13, 2014 22:40
Coderbyte Challenge SecondGreatLow
/* Coderbyte Challenge
Using the JavaScript language, have the function SecondGreatLow(arr) take the array of numbers stored in arr
and return the second lowest and second greatest numbers, respectively, separated by a space.
For example: if arr contains [7, 7, 12, 98, 106] the output should be 12 98.
The array will not be empty and will contain at least 2 numbers.
*/
function SecondGreatLow(arr) {
@areagray
areagray / divisionStringified
Created January 14, 2014 04:25
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);
@areagray
areagray / countingMinutes1.js
Created January 14, 2014 15:27
Coderbyte: Using the JavaScript language, have the function CountingMinutesI(str) take the str parameter being passed which will be two times (each properly formatted with a colon and am or pm) separated by a hyphen and return the total number of minutes between the two times. The time will be in a 12 hour clock format. For example: if str is 9:…
//Coderbyte Challenge
function CountingMinutesI(str) {
var when,
offset,
mins,
segments = [],
ampm,
hours,
@areagray
areagray / meanMode.js
Created January 14, 2014 17:02
Using the JavaScript language, have the function MeanMode(arr) take the array of numbers stored in arr and return 1 if the mode equals the mean, 0 if they don't equal each other (ie. [5, 3, 3, 3, 1] should return 1 because the mode (3) equals the mean (3)). The array will not be empty, will only contain positive integers, and will not contain m…
//Coderbyte
function MeanMode(arr) {
var sum=0,
mean, mode, midpoint, modeStr, re,
champTotal=0;
//old faithful
arr.sort(function(a, b) {
return a - b;
@areagray
areagray / dashInsert.js
Created January 18, 2014 17:20
Coderbyte: Have the function DashInsert(num) insert dashes ('-') between each two odd numbers in num. For example: if num is 454793 the output should be 4547-9-3. Don't count zero as an odd number.
//coderbyte
function DashInsert(num) {
var prev='',
newstring='';
num = num.toString();
for (var i=0; i<num.length; i++){
@areagray
areagray / swapCase.js
Last active September 27, 2022 08:42
Coderbyte: Have the function SwapCase(str) take the str parameter and swap the case of each character. For example: if str is "Hello World" the output should be hELLO wORLD. Let numbers and symbols stay the way they are.
//coderbyte
function SwapCase(str) {
var newChar='',
newString='';
newString = str.replace(/./g, function(myChar){
//use the replace to iterate and rebuild string
if (myChar.match(/[a-z]/)){
@areagray
areagray / numberAddition.js
Created January 19, 2014 19:01
Coderbyte: Have the function NumberSearch(str) take the str parameter, search for all the numbers in the string, add them together, then return that final number. For example: if str is "88Hello 3World!" the output should be 91. You will have to differentiate between single digit numbers and multiple digit numbers like in the example above. So "…
//coderbyte
function NumberAddition(str) {
var mathches,
total=0;
// use regexp to grab the numbers
matches=str.match(/([\d]+)/g);
//itereate and add
@areagray
areagray / thirdGreatest.js
Created January 21, 2014 22:27
Coderbyte: Have the function ThirdGreatest(strArr) take the array of strings stored in strArr and return the third largest word within in. So for example: if strArr is ["hello", "world", "before", "all"] your output should be world because "before" is 6 letters long, and "hello" and "world" are both 5, but the output should be world because it a…
//Coderbyte
function ThirdGreatest(strArr) {
var matrix=[];
//build the array, two dimensions
for (var i=0; i<strArr.length;i++){
matrix.push([strArr[i].length,strArr[i]]);