Skip to content
Open
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
108 changes: 54 additions & 54 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
import { beforeEach, test, expect } from '@jest/globals';
import { execFileSync } from 'child_process';
import { fileURLToPath } from "node:url";
import path from "node:path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
let rows1;
let rows2;
beforeEach(() => {
const options = { encoding: 'utf8', cwd: path.join(__dirname, '..') };
const result1 = execFileSync(
'bin/weather.js',
['__fixtures__/weather1.csv'],
options,
);
rows1 = result1.trim().split('\n')
const result2 = execFileSync(
'bin/weather.js',
['__fixtures__/weather2.csv'],
options,
);
rows2 = result2.trim().split('\n')
});
test('step1', () => {
expect(rows1[0]).toEqual('Count: 20');
expect(rows2[0]).toEqual('Count: 9');
});
test('step2', () => {
expect(rows1[1]).toEqual('Cities: Chicago, Denver, Los Angeles, Miami, Seattle');
expect(rows2[1]).toEqual('Cities: Chicago, Denver, Miami, Seattle');
});
test('step3', () => {
expect(rows1[2]).toEqual('Humidity: Min: 58, Max: 80');
expect(rows2[2]).toEqual('Humidity: Min: 30, Max: 83');
});
test('step4', () => {
expect(rows1[3]).toEqual('HottestDay: 2023-04-18 Los Angeles');
expect(rows2[3]).toEqual('HottestDay: 2023-04-18 Miami');
});
test('step5', () => {
expect(rows1[4]).toEqual('HottestCity: Miami');
expect(rows2[4]).toEqual('HottestCity: Miami');
});
import { beforeEach, test, expect } from '@jest/globals';

import { execFileSync } from 'child_process';
import { fileURLToPath } from "node:url";
import path from "node:path";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

let rows1;
let rows2;

beforeEach(() => {
const options = { encoding: 'utf8', cwd: path.join(__dirname, '..') };

const result1 = execFileSync(
'bin/weather.js',
['__fixtures__/weather1.csv'],
options,
);
rows1 = result1.trim().split('\n')

const result2 = execFileSync(
'bin/weather.js',
['__fixtures__/weather2.csv'],
options,
);
rows2 = result2.trim().split('\n')
});

test('step1', () => {
expect(rows1[0]).toEqual('Count: 20');
expect(rows2[0]).toEqual('Count: 9');
});

test('step2', () => {
expect(rows1[1]).toEqual('Cities: Chicago, Denver, Los Angeles, Miami, Seattle');
expect(rows2[1]).toEqual('Cities: Chicago, Denver, Miami, Seattle');
});

test('step3', () => {
expect(rows1[2]).toEqual('Humidity: Min: 58, Max: 80');
expect(rows2[2]).toEqual('Humidity: Min: 30, Max: 83');
});

test('step4', () => {
expect(rows1[3]).toEqual('HottestDay: 2023-04-18 Los Angeles');
expect(rows2[3]).toEqual('HottestDay: 2023-04-18 Miami');
});

test('step5', () => {
expect(rows1[4]).toEqual('HottestCity: Miami');
expect(rows2[4]).toEqual('HottestCity: Miami');
});
45 changes: 23 additions & 22 deletions bin/weather.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#!/usr/bin/env node

import { fileURLToPath } from "node:url";
import path from "node:path";
import fs from 'fs';
import _ from 'lodash';
import solution from "../index.js";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);


const fileName = process.argv[2];
const content = fs.readFileSync(path.join(
__dirname,
'..',
fileName
), 'utf-8');

// BEGIN

// END
#!/usr/bin/env node

import { fileURLToPath } from "node:url";
import path from "node:path";
import fs from 'fs';
import _ from 'lodash';
import solution from "../index.js";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);


const fileName = process.argv[2];
const content = fs.readFileSync(path.join(
__dirname,
'..',
fileName
), 'utf-8');

// BEGIN
solution(content);

// END
51 changes: 47 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@
export default function solution(content){
// BEGIN

// END
import getData from './src/utils.js'

export default function solution(content){
// BEGIN
const data = getData(content);
const count = data.length;
console.log(`Count: ${count}`);

//TASK2
const cities = [];

data.map((item) => {
if (!cities.includes(item[7])) {cities.push(item[7])}
});
cities.sort();
console.log(`Cities: ${cities.join(', ')}`);

//TASK3
const minHum = 100;
const maxHum = 0;

const max = data.reduce((acc, item) => {
return Number(item[3]) >= acc? acc = Number(item[3]): acc;
}, 0);
const min = data.reduce((acc, item) => {
return Number(item[3]) <= acc? acc = Number(item[3]): acc;
}, 100);

console.log(`Humidity: Min: ${min}, Max: ${max}`);

//TASK4
const result4 = data.reduce((preVal, curVal) => {
return curVal[1] > preVal[1] ? curVal: preVal;
});

console.log(`HottestDay: ${result4[0]} ${result4[7]}`);

//TASK5
const result5 = data.reduce((preVal, curVal) => {
const overagePre = (Number(preVal[1]) + Number(preVal[2])) / 2;
const overageCur = (Number(curVal[1]) + Number(curVal[2])) / 2;
return overageCur >= overagePre ? curVal: preVal;
});

console.log(`HottestCity: ${result5[7]}`);

// END
}
Loading