Check Nums Coderbyte Solution

0

Have the function CheckNums(num1,num2) take both parameters being passed and return the string true if num2 is greater than num1, otherwise return the string false. If the parameter values are equal to each other then return the string -1.

Check Nums Coderbyte In Java

import java.util.Scanner;

public class CheckNums {
String CheckNums(int num1, int num2){
if (num2 > num1) {
return "true";
} else if (num2 < num1) {
return "false";
}

return "-1";

}

public static void main(String[] args){
// keep this function call here
Scanner s = new Scanner(System.in);
CheckNums c = new CheckNums();
System.out.print(c.CheckNums(s.nextInt(),s.nextInt()));
}
}

Check Nums Coderbyte JavaScript

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:00am-10:00am then the output should be 60. If str is 1:00pm-11:00am the output should be 1320.  


function CountingMinutesI(str) {
var time1Obj = {}, time2Obj = {}, timeDiff;
time1Obj = setTimeObject(str, 0);
time2Obj = setTimeObject(str, 1);
if (time1Obj.ampm == time2Obj.ampm && time1Obj.tot > time2Obj.tot) {
timeDiff = (((12 - time1Obj.hours + 12) * 60) - (time1Obj.mins)) + ((time2Obj.hours * 60) + time2Obj.mins);
}
else if (time1Obj.ampm == time2Obj.ampm && time1Obj.tot < time2Obj.tot) {
timeDiff = ((time2Obj.hours * 60) + time2Obj.mins) - ((time1Obj.hours * 60) + time1Obj.mins);
}
else if (time1Obj.ampm !== time2Obj.ampm && time1Obj.ampm === "am") {
timeDiff = (((12 - time1Obj.hours) * 60) - time1Obj.mins) + ((time2Obj.hours * 60) + time2Obj.mins);
}
else {
timeDiff = (((12 - time1Obj.hours) * 60) - time1Obj.mins) + ((time2Obj.hours * 60) + time2Obj.mins);
}

return timeDiff;
}
function setTimeObject(str, num) {
var arr = str.split("-");
var tObject = {};
tObject.hours = Number(arr[num].slice(0,arr[num].length-2).split(":")[0]);
tObject.mins = Number(arr[num].slice(0,arr[num].length-2).split(":")[1]);
tObject.ampm = arr[num].slice(-2);
tObject.tot = tObject.hours * 100 + tObject.mins;
return tObject;
}

Disclaimer: The above Problem is generated by Coderbyte but the Solution is provided by ShouterFolk.


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)
Our website uses cookies to enhance your experience. Learn More
Accept !