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
1 change: 1 addition & 0 deletions requirement-sets/1-reading-writing-files/answer.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
count: 3
24 changes: 23 additions & 1 deletion requirement-sets/1-reading-writing-files/src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
// run the program
const fs = require('fs');

const data = fs.readFileSync('../input.txt');
const dataArray = data.toString().toUpperCase().trim().split('\r\n');
console.log(dataArray);

function checkPosition(data) {
let count = 0;
dataArray.forEach((el) => {
const counts = { W: 0, E: 0, N: 0, S: 0 };
el.split('').forEach((letter) => (counts[letter] += 1));
if (counts.W === counts.E && counts.S === counts.N) count += 1;
});
const output = `count: ${count}`;
fs.writeFile('../answer.txt', output, (err) => {
if (err) {
console.error(err);
}
});
return count;
}

console.log(checkPosition(data));
14 changes: 6 additions & 8 deletions requirement-sets/2-coding-tests/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ module.exports = {
env: {
commonjs: true,
es2021: true,
node: true
node: true,
jasmine: true,
},
extends: [
'standard'
],
extends: ['standard'],
parserOptions: {
ecmaVersion: 'latest'
ecmaVersion: 'latest',
},
rules: {
}
}
rules: {},
};
121 changes: 120 additions & 1 deletion requirement-sets/2-coding-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions requirement-sets/2-coding-tests/spec/longest-sequence.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const longestSequence = require('../src/longest-sequence.js');

describe('Longest sequence', () => {
it('scenario 1', () => {
expect(longestSequence('dghhhmhmx')).toEqual({ h: 3 });
});
it('scenario 2', () => {
expect(longestSequence('dhkkhhKKKt')).toEqual({ k: 3 });
});
it('scenario 3', () => {
expect(longestSequence('aBbBadddadd')).toEqual({ b: 3 });
});
it('scenario 4', () => {
expect(longestSequence('gggttrfdesdcxzzzzzzzzzz')).toEqual({ z: 10 });
});
it('scenario 5', () => {
expect(longestSequence('jshetdrefdddesawwesdcxzwwwwwwwwww')).toEqual({
w: 10,
});
});
});
30 changes: 30 additions & 0 deletions requirement-sets/2-coding-tests/src/longest-sequence.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const longestSequence = (str) => {
let longestSequence = { a: 0 }
let currentSequence = {}

for (let i = 0; i < str.length - 1; i++) {
const char = str[i].toLowerCase()
const nextChar = str[i + 1].toLowerCase()

if (!currentSequence[char]) {
currentSequence = {}
currentSequence[char] = 1
}

if (char === nextChar) {
currentSequence[char] += 1
}
if (Object.values(currentSequence)[0] > Object.values(longestSequence)[0]) {
longestSequence = { ...currentSequence }
} else if (
Object.values(currentSequence)[0] === Object.values(longestSequence)[0]
) {
if (Object.keys(currentSequence)[0] < Object.keys(longestSequence)[0]) {
longestSequence = { ...currentSequence }
}
}
}
return longestSequence
}

module.exports = longestSequence
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,19 @@ GET https://api.npms.io/v2/search/suggestions?q=react

*/

const axios = require('axios');

module.exports = async function countMajorVersionsAbove10() {
// TODO
try {
const { data } = await axios.get(
'https://api.npms.io/v2/search/suggestions?q=react'
);
const answer = data
.map((el) => el.package.version.split('.')[0])
.filter((el) => Number(el) >= 10).length;

return number
return answer;
} catch (err) {
console.log(err);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,22 @@ GET https://api.npms.io/v2/search/suggestions?q=react
* the "name" of the package that has the oldest "date" value

*/
const axios = require('axios');

module.exports = async function oldestPackageName() {
// TODO
try {
const { data } = await axios.get(
'https://api.npms.io/v2/search/suggestions?q=react'
);

return name
const name = data
.map((el) => [el.package.date, el.package.name])
.reduce((previous, current) => {
return previous[0] < current[0] ? previous : current;
})[1];

return name;
} catch (err) {
console.log(err);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

* Make the following HTTP request with either axios or node-fetch:

/*

* Make the following HTTP request with either axios or node-fetch:

GET https://api.npms.io/v2/search/suggestions?q=react

******
Expand All @@ -23,8 +27,32 @@ GET https://api.npms.io/v2/search/suggestions?q=react

*/

module.exports = async function organiseMaintainers() {
// TODO
const axios = require('axios');

return maintainers
module.exports = async function organiseMaintainers() {
let maintainers = [];

const { data } = await axios.get(
'https://api.npms.io/v2/search/suggestions?q=react'
);

data.forEach((dep) => {
dep.package.maintainers.forEach((maintainer) => {
const record = maintainers.find((obj) => {
return obj.username === maintainer.username;
});
if (!record) {
const newRecord = {
username: maintainer.username,
packageNames: [dep.package.name],
};
maintainers.push(newRecord);
} else {
record.packageNames.push(dep.package.name);
}
});
});

// console.log('DATA : ', JSON.stringify(data[0], null, 2));
return maintainers;
};