File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ // coderbyte solution for counting minutes
2
+ // splashinn
3
+
4
+ function lateOrNot ( str ) {
5
+ for ( var i = 0 ; i < str . length ; i ++ ) {
6
+ if ( str [ i ] === "p" || str [ i ] === "P" ) {
7
+ return "p" ;
8
+ } else if ( str [ i ] === "a" || str [ i ] === "A" ) {
9
+ return "a" ;
10
+ }
11
+ }
12
+ }
13
+
14
+
15
+
16
+
17
+ function toMinutes ( time ) {
18
+ var arr = time . split ( ":" ) ;
19
+ if ( arr [ 0 ] === "12" ) {
20
+ arr [ 0 ] = "00" ;
21
+ }
22
+ var min = parseInt ( arr [ 1 ] , 10 ) ;
23
+ var hours = parseInt ( arr [ 0 ] , 10 ) * 60 ;
24
+ if ( lateOrNot ( time ) === "p" ) {
25
+ hours += 12 * 60 ;
26
+ }
27
+ return hours + min ;
28
+ }
29
+
30
+
31
+
32
+
33
+ function countingMinutes ( str ) {
34
+ var array = str . split ( "-" ) ;
35
+ var time1 = toMinutes ( array [ 0 ] ) ;
36
+ var time2 = toMinutes ( array [ 1 ] ) ;
37
+ if ( time2 < time1 ) {
38
+ return time2 + ( 24 * 60 - time1 ) ;
39
+ } else {
40
+ return time2 - time1 ;
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments