Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] logger export added. #124

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hackerrank/implementation/betweenTwoSets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
* 4, 8 and 16 are the only three numbers for which each element of a is a factor and each is a factor of all elements of b.
*/

// import logger from '../../logger';
// import { logger as console } from '../../logger';

export function isFactor(n: number, group: number[]): boolean {
let result = true;
Expand Down
10 changes: 5 additions & 5 deletions src/hackerrank/implementation/birthday.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,20 @@
* constraint, we print 1 as our answer.
*/

import logger from '../../logger';
import { logger as console } from '../../logger';

export function birthday(s: number[], d: number, m: number): number {
let result = 0;
logger.debug(`s: ${s}`);
console.debug(`s: ${s}`);

for (let i = 0; i <= s.length - m; i++) {
let sum = 0;
logger.debug('-------------------------------');
console.debug('-------------------------------');
for (let j = i; j < i + m; j++) {
logger.debug(`j: s[${j}] => ${s[j]}`);
console.debug(`j: s[${j}] => ${s[j]}`);
sum += s[j];
}
logger.debug('-------------------------------');
console.debug('-------------------------------');
if (sum === d) result += 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/hackerrank/implementation/breakingRecords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
* she earned during her first game), so we print 4 0 as our answer.
*/

// import logger from '../../logger';
// import { logger as console } from '../../logger';

export function breakingRecords(scores: number[]): number[] {
if (scores.length == 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/hackerrank/implementation/countingValleys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@
* The hiker enters and leaves one valley.
*/

import logger from '../../logger';
import { logger as console } from '../../logger';

export function countingValleys(steps: number, path: string): number {
const stepList = path.split('');
let altitude = 0;
let valleys = 0;

logger.debug(stepList);
console.debug(stepList);

stepList.forEach((step) => {
if (step === 'D') {
Expand Down
4 changes: 2 additions & 2 deletions src/hackerrank/implementation/divisibleSumPairs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@
* (4,5) -> ar[4] + ar[5] = 1 + 2 = 3
*/

import logger from '../../logger';
import { logger as console } from '../../logger';

export function divisibleSumPairs(n: number, k: number, ar: number[]): number {
let pairs = 0;
for (let i = 0; i < ar.length; i++) {
for (let j = i + 1; j < ar.length; j++) {
if ((ar[i] + ar[j]) % k === 0) {
logger.debug(`i: ${i} => ${ar[i]} | j: ${j} => ${ar[j]}`);
console.debug(`i: ${i} => ${ar[i]} | j: ${j} => ${ar[j]}`);
pairs += 1;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/hackerrank/implementation/migratoryBirds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
* Two types have a frequency of 3, and the lower of those is type 3.
*/

import logger from '../../logger';
import { logger as console } from '../../logger';

interface Birds {
[name: string]: number;
Expand All @@ -96,22 +96,22 @@ export function migratoryBirds(arr: number[]): number {
let max = arr[0];

for (const bird of arr) {
logger.debug(`bird ${bird}`);
console.debug(`bird ${bird}`);

if (!map[bird]) {
map[bird] = 1;
} else {
map[bird] += 1;
}

logger.debug(`bird = ${bird} ~> map[bird] = ${map[bird]}`);
logger.debug(`max = ${max} ~> map[max] = ${map[max]}`);
console.debug(`bird = ${bird} ~> map[bird] = ${map[bird]}`);
console.debug(`max = ${max} ~> map[max] = ${map[max]}`);

if (map[bird] > map[max] || (map[bird] == map[max] && bird < max))
max = bird;
}

logger.debug(`map: ${map}`);
console.debug(`map: ${map}`);

return max;
}
Expand Down
4 changes: 2 additions & 2 deletions src/hackerrank/implementation/repeatedString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
* are a, we return 1000000000000.
*/

import logger from '../../logger';
import { logger as console } from '../../logger';

export function countAs(word: string): number {
let result = 0;
Expand All @@ -96,7 +96,7 @@ export function repeatedString(s: string, n: number): number {
const countBlocks = Math.floor(n / blockSize);
const restSize = Math.floor(n % blockSize);

logger.debug(`countBlocks: ${countBlocks} + rest: ${restSize}`);
console.debug(`countBlocks: ${countBlocks} + rest: ${restSize}`);

result = countAs(s) * countBlocks + countAs(s.substr(0, restSize));
return result;
Expand Down
6 changes: 3 additions & 3 deletions src/hackerrank/implementation/sockMerchant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
* There are three pairs of socks.
*/

import logger from '../../logger';
import { logger as console } from '../../logger';

export function sockMerchant(n: number, ar: number[]): number {
let result = 0;
Expand All @@ -80,11 +80,11 @@ export function sockMerchant(n: number, ar: number[]): number {
matches[v] = matches?.[v] ? matches[v] + 1 : 1;
});

logger.debug(matches);
console.debug(matches);

let k: keyof Matches;
for (k in matches) {
logger.debug(matches[k]);
console.debug(matches[k]);

result += Math.floor(matches[k] / 2);
}
Expand Down
1 change: 1 addition & 0 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ logger.info('LOG: INFO LEVEL ENABLED');
logger.info(`LOG LEVEL: ${logger.levelVal}`);

export default logger;
export { logger };