File tree 7 files changed +155
-0
lines changed
7 files changed +155
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * Complete the 'bonAppetit' function below.
3
+ *
4
+ * The function accepts following parameters:
5
+ * 1. INTEGER_ARRAY bill
6
+ * 2. INTEGER k
7
+ * 3. INTEGER b
8
+ */
9
+
10
+ function bonAppetit ( bill , k , b ) {
11
+ // Write your code here
12
+ bill . splice ( k , 1 ) ;
13
+ let sommeTab = bill . reduce ( ( a , b ) => a + b , 0 ) ;
14
+ let bAnna ;
15
+ bAnna = sommeTab / 2 ;
16
+ if ( bAnna == b ) {
17
+ console . log ( 'Bon Appetit' ) ;
18
+ } else {
19
+ console . log ( Math . abs ( bAnna - b ) ) ;
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Complete the 'dayOfProgrammer' function below.
3
+ *
4
+ * The function is expected to return a STRING.
5
+ * The function accepts INTEGER year as parameter.
6
+ */
7
+
8
+ function dayOfProgrammer ( year ) {
9
+ // Write your code here
10
+ if ( year >= 1700 && year <= 1917 ) {
11
+ if ( year % 4 == 0 ) {
12
+ return ( "12.09." + year ) ;
13
+ } else {
14
+ return ( "13.09." + year ) ;
15
+ }
16
+ } else if ( year == 1918 ) {
17
+ return ( "26.09." + year ) ;
18
+ } else if ( year > 1918 ) {
19
+ if ( year % 400 == 0 || ( year % 4 == 0 && year % 100 != 0 ) ) {
20
+ return ( "12.09." + year ) ;
21
+ } else {
22
+ return ( "13.09." + year ) ;
23
+ }
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Complete the 'divisibleSumPairs' function below.
3
+ *
4
+ * The function is expected to return an INTEGER.
5
+ * The function accepts following parameters:
6
+ * 1. INTEGER n
7
+ * 2. INTEGER k
8
+ * 3. INTEGER_ARRAY ar
9
+ */
10
+
11
+ function divisibleSumPairs ( n , k , ar ) {
12
+ // Write your code here
13
+ let count = 0 ;
14
+ for ( let i = 0 ; i < ar . length ; i ++ ) {
15
+ for ( let j = i + 1 ; j < ar . length ; j ++ ) {
16
+ ( ar [ i ] + ar [ j ] ) % k == 0 && count ++ ;
17
+ }
18
+ }
19
+ return count ;
20
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Complete the 'pageCount' function below.
3
+ *
4
+ * The function is expected to return an INTEGER.
5
+ * The function accepts following parameters:
6
+ * 1. INTEGER n
7
+ * 2. INTEGER p
8
+ */
9
+
10
+ function pageCount ( n , p ) {
11
+ // Write your code here
12
+ let startCount = Math . floor ( p / 2 ) ;
13
+ let stopCount = Math . floor ( ( n / 2 ) - startCount ) ;
14
+
15
+ let result = Math . min ( startCount , stopCount ) ;
16
+ return result ;
17
+
18
+
19
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Complete the 'migratoryBirds' function below.
3
+ *
4
+ * The function is expected to return an INTEGER.
5
+ * The function accepts INTEGER_ARRAY arr as parameter.
6
+ */
7
+
8
+ function migratoryBirds ( arr ) {
9
+ // Write your code here
10
+ let maxVal = 0 ;
11
+ let objectArr = arr . reduce ( ( obj , b ) => {
12
+ obj [ b ] = ++ obj [ b ] || 1 ;
13
+ return obj ;
14
+ } , { } ) ;
15
+
16
+ maxVal = Math . max ( ...Object . values ( objectArr ) ) ;
17
+ let res = Object . keys ( objectArr ) . find ( key => objectArr [ key ] === maxVal ) ;
18
+ return parseInt ( res ) ;
19
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Complete the 'sockMerchant' function below.
3
+ *
4
+ * The function is expected to return an INTEGER.
5
+ * The function accepts following parameters:
6
+ * 1. INTEGER n
7
+ * 2. INTEGER_ARRAY ar
8
+ */
9
+
10
+ function sockMerchant ( n , ar ) {
11
+ // Write your code here
12
+ const uniqueValues = [ ... new Set ( ar ) ] ;
13
+ let count = 0 ;
14
+ uniqueValues . forEach ( value => {
15
+ const filterValues = ar . filter ( element => element == value )
16
+ const pairsNumber = Math . floor ( filterValues . length / 2 )
17
+ count += pairsNumber
18
+ } )
19
+ return count ;
20
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Complete the 'birthday' function below.
3
+ *
4
+ * The function is expected to return an INTEGER.
5
+ * The function accepts following parameters:
6
+ * 1. INTEGER_ARRAY s
7
+ * 2. INTEGER d
8
+ * 3. INTEGER m
9
+ */
10
+
11
+ function birthday ( s , d , m ) {
12
+ // Write your code here
13
+ let num = s ;
14
+ let nums = [ ] ;
15
+ let count = 0 ;
16
+ const add = ( arr ) => arr . reduce ( ( a , b ) => a + b , 0 ) ;
17
+ for ( let i = 0 ; i < s . length ; i ++ ) {
18
+ let tempTab = num . slice ( 0 + i , m + i ) ;
19
+ nums . push ( tempTab ) ;
20
+ }
21
+ if ( num . length === 1 && num [ 0 ] === d ) {
22
+ count ++ ;
23
+ } else {
24
+ nums . forEach ( ( item ) => {
25
+ if ( add ( item ) === d ) {
26
+ count ++ ;
27
+ }
28
+ } ) ;
29
+ }
30
+ return count ;
31
+ }
You can’t perform that action at this time.
0 commit comments