refactor: Renamed js to nodejs
- feat: Added util module
This commit is contained in:
		| @@ -17,6 +17,8 @@ Note: | |||||||
| Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows. | Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows. | ||||||
| */ | */ | ||||||
| 
 | 
 | ||||||
|  | const { assert }  = require('../../util/js');  | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * @param {number} x |  * @param {number} x | ||||||
|  * @return {number} |  * @return {number} | ||||||
| @@ -40,18 +42,21 @@ const reverse = function(x) { | |||||||
|  * Output: 321 |  * Output: 321 | ||||||
|  */ |  */ | ||||||
| x = 123; | x = 123; | ||||||
| console.log(reverse(x)); | sol = 321; | ||||||
|  | assert(reverse(x) === sol, 'Output: 321'); | ||||||
| 
 | 
 | ||||||
| /* Test Case 2 | /* Test Case 2 | ||||||
|  * Input: -123 |  * Input: -123 | ||||||
|  * Output: -321 |  * Output: -321 | ||||||
|  */ |  */ | ||||||
| x = -123; | x = -123; | ||||||
| console.log(reverse(x)); | sol = -321 | ||||||
|  | assert(reverse(x) === sol, 'Output: -321'); | ||||||
| 
 | 
 | ||||||
| /* Test Case 3 | /* Test Case 3 | ||||||
|  * Input: 120 |  * Input: 120 | ||||||
|  * Output: 21 |  * Output: 21 | ||||||
|  */ |  */ | ||||||
| x = 120; | x = 120; | ||||||
| console.log(reverse(x)); | sol = 21; | ||||||
|  | assert(reverse(x) == sol, 'Output: 21'); | ||||||
| @@ -17,12 +17,7 @@ | |||||||
|  * Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. If the numerical value is out of the range of representable values, INT_MAX (231 − 1) or INT_MIN (−231) is returned. |  * Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. If the numerical value is out of the range of representable values, INT_MAX (231 − 1) or INT_MIN (−231) is returned. | ||||||
| 
 | 
 | ||||||
| */ | */ | ||||||
| const assert = function(condition, message) { | const { assert }  = require('../../util/js');  | ||||||
|   if(!condition) { |  | ||||||
|     console.error(` ${message}`); |  | ||||||
|   } |  | ||||||
|   console.log(` ${message}`); |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * @param {string} str |  * @param {string} str | ||||||
							
								
								
									
										8
									
								
								util/js/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								util/js/index.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | |||||||
|  | module.exports.assert = (condition, message) => { | ||||||
|  |   if(condition) { | ||||||
|  |     console.log(` ${message}`); | ||||||
|  |   } | ||||||
|  |   else { | ||||||
|  |     console.error(` ${message}`); | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -25,6 +25,7 @@ Y A   H R | |||||||
| P     I | P     I | ||||||
| */ | */ | ||||||
| 
 | 
 | ||||||
|  | const { assert }  = require('../../util/js');  | ||||||
| /** | /** | ||||||
|  * @param {string} s |  * @param {string} s | ||||||
|  * @param {number} numRows |  * @param {number} numRows | ||||||
| @@ -95,7 +96,8 @@ let s, numRows; | |||||||
| 
 | 
 | ||||||
| s = 'PAYPALISHIRING'; | s = 'PAYPALISHIRING'; | ||||||
| numRows = 3; | numRows = 3; | ||||||
| console.log(convert(s, numRows)); | sol = 'PAHNAPLSIIGYIR'; | ||||||
|  | assert(convert(s, numRows) == sol, 'Output: "PAHNAPLSIIGYIR"'); | ||||||
| 
 | 
 | ||||||
| /* Test Case 2 | /* Test Case 2 | ||||||
|  * Input: s = "PAYPALISHIRING", numRows = 4 |  * Input: s = "PAYPALISHIRING", numRows = 4 | ||||||
| @@ -103,7 +105,8 @@ console.log(convert(s, numRows)); | |||||||
|  */ |  */ | ||||||
| s =  'PAYPALISHIRING'; | s =  'PAYPALISHIRING'; | ||||||
| numRows = 4; | numRows = 4; | ||||||
| console.log(convert(s, numRows)); | sol = 'PINALSIGYAHRPI'; | ||||||
|  | assert(convert(s, numRows) == sol, 'Output: "PINALSIGYAHRPI"'); | ||||||
| 
 | 
 | ||||||
| /* Test Case 3 | /* Test Case 3 | ||||||
|  * Input: s = "AB", numRows = 1 |  * Input: s = "AB", numRows = 1 | ||||||
| @@ -111,4 +114,5 @@ console.log(convert(s, numRows)); | |||||||
|  */ |  */ | ||||||
| s =  'AB'; | s =  'AB'; | ||||||
| numRows = 1; | numRows = 1; | ||||||
| console.log(convert(s, numRows)); | sol = 'AB'; | ||||||
|  | assert(convert(s, numRows) == sol, 'Output: "AB"'); | ||||||
		Reference in New Issue
	
	Block a user