File tree Expand file tree Collapse file tree 3 files changed +111
-0
lines changed
Hackerrank solutions/10 days of js Expand file tree Collapse file tree 3 files changed +111
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ process . stdin . resume ( ) ;
4
+ process . stdin . setEncoding ( 'utf-8' ) ;
5
+
6
+ let inputString = '' ;
7
+ let currentLine = 0 ;
8
+
9
+ process . stdin . on ( 'data' , inputStdin => {
10
+ inputString += inputStdin ;
11
+ } ) ;
12
+
13
+ process . stdin . on ( 'end' , _ => {
14
+ inputString = inputString . trim ( ) . split ( '\n' ) . map ( string => {
15
+ return string . trim ( ) ;
16
+ } ) ;
17
+
18
+ main ( ) ;
19
+ } ) ;
20
+
21
+ function readLine ( ) {
22
+ return inputString [ currentLine ++ ] ;
23
+ }
24
+
25
+ /*
26
+ * Modify and return the array so that all even elements are doubled and all odd elements are tripled.
27
+ *
28
+ * Parameter(s):
29
+ * nums: An array of numbers.
30
+ */
31
+ function modifyArray ( nums ) {
32
+ var something = function ( n ) {
33
+ if ( n % 2 == 0 )
34
+ return n * 2 ;
35
+ else
36
+ return n * 3 ;
37
+
38
+ }
39
+ var newArray = nums . map ( something ) ;
40
+ return newArray ;
41
+ }
42
+
43
+
44
+ function main ( ) {
45
+ const n = + ( readLine ( ) ) ;
46
+ const a = readLine ( ) . split ( ' ' ) . map ( Number ) ;
47
+
48
+ console . log ( modifyArray ( a ) . toString ( ) . split ( ',' ) . join ( ' ' ) ) ;
49
+ }
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ process . stdin . resume ( ) ;
4
+ process . stdin . setEncoding ( 'utf-8' ) ;
5
+
6
+ let inputString = '' ;
7
+ let currentLine = 0 ;
8
+
9
+ process . stdin . on ( 'data' , inputStdin => {
10
+ inputString += inputStdin ;
11
+ } ) ;
12
+
13
+ process . stdin . on ( 'end' , _ => {
14
+ inputString = inputString . trim ( ) . split ( '\n' ) . map ( string => {
15
+ return string . trim ( ) ;
16
+ } ) ;
17
+
18
+ main ( ) ;
19
+ } ) ;
20
+
21
+ function readLine ( ) {
22
+ return inputString [ currentLine ++ ] ;
23
+ }
24
+
25
+ function getMaxLessThanK ( n , k )
26
+ {
27
+ let max = 0
28
+ for ( let i = 1 ; i < n ; i ++ )
29
+ for ( let j = i + 1 ; j <= n ; j ++ )
30
+ {
31
+ let and = i & j
32
+
33
+ if ( and < k && and > max )
34
+ max = and
35
+ }
36
+ return max
37
+ }
38
+
Original file line number Diff line number Diff line change
1
+ class Rectangle {
2
+ constructor ( w , h ) {
3
+ this . w = w ;
4
+ this . h = h ;
5
+ }
6
+ }
7
+
8
+ /*
9
+ * Write code that adds an 'area' method to the Rectangle class' prototype
10
+ */
11
+ Rectangle . prototype . area = function ( ) {
12
+ return this . w * this . h ;
13
+ }
14
+ /*
15
+ * Create a Square class that inherits from Rectangle and implement its class constructor
16
+ */
17
+ //inherit from rectangle
18
+ class Square extends Rectangle {
19
+ //create Square constructor
20
+ constructor ( a ) {
21
+ //call constructor from Rectangle class and insert value
22
+ super ( a , a ) ;
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments