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
249 changes: 249 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
{
"parser": "@typescript-eslint/parser",
"extends": [
"airbnb",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"env": {
"browser": true
},
"globals": {},
"rules": {
"yoda": "warn",
"import/no-named-as-default": 0,
"@typescript-eslint/no-use-before-define": [
"error",
{
"functions": false
}
],
"@typescript-eslint/no-empty-function": [
"off"
],
"@typescript-eslint/no-explicit-any": [
"warn"
],
"@typescript-eslint/interface-name-prefix": [
"off"
],
"@typescript-eslint/explicit-function-return-type": [
"off",
{
"allowTypedFunctionExpressions": true,
"allowExpressions": true
}
],
"jsx-a11y/label-has-for": [
2,
{
"components": [
"Label"
],
"required": {
"every": [
"nesting",
"id"
]
},
"allowChildren": true
}
],
"jsx-a11y/label-has-associated-control": [
2,
{
"labelAttributes": [
"label"
],
"controlComponents": [
"Input"
],
"depth": 3
}
],
"jsx-a11y/click-events-have-key-events": "warn",
"jsx-a11y/anchor-is-valid": "warn",
"dot-location": [
1,
"property"
],
"camelcase": [
2,
{
"properties": "always",
"allow": [
"UNSAFE_componentWillReceiveProps",
"UNSAFE_componentWillMount",
"UNSAFE_componentWillUpdate"
]
}
],
"max-len": [
"error",
{
"code": 100,
"ignoreStrings": true,
"ignoreComments": true,
"tabWidth": 2,
"ignoreTemplateLiterals": true
}
],
"no-underscore-dangle": 0,
"no-return-assign": [
"error",
"except-parens"
],
"key-spacing": 0,
"arrow-parens": [
1,
"always"
],
"generator-star-spacing": [
"error",
"both"
],
"no-confusing-arrow": [
"error",
{
"allowParens": true
}
],
"no-param-reassign": [
"error",
{
"props": false
}
],
"no-nested-ternary": [
"warn"
],
"func-names": [
"error",
"as-needed"
],
"react/sort-comp": 0,
"react/jsx-filename-extension": [
"error",
{
"extensions": [
".jsx",
".tsx"
]
}
],
"react/destructuring-assignment": 0,
"no-use-before-define": [
"error",
"nofunc"
],
"import/first": [
"off"
],
"jsx-a11y/no-static-element-interactions": 0,
"no-mixed-operators": [
"error",
{
"allowSamePrecedence": true
}
],
"newline-per-chained-call": [
"error"
],
"react/no-access-state-in-setstate": "warn",
"react-hooks/rules-of-hooks": "warn",
"react-hooks/exhaustive-deps": "warn",
"react/prefer-stateless-function": [
"warn"
],
"react/no-unused-state": [
"error"
],
"import/no-named-as-default-member": [
"warn"
],
"prefer-arrow-callback": "off",
"prefer-destructuring": [
"warn",
{
"VariableDeclarator": {
"array": false,
"object": true
},
"AssignmentExpression": {
"array": true,
"object": false
}
}
],
"no-plusplus": [
"error",
{
"allowForLoopAfterthoughts": true
}
],
"no-unused-expressions": [
"error",
{
"allowTernary": true
}
],
"no-console": [
"error",
{
"allow": [
"error",
"warn"
]
}
],
"no-only-tests/no-only-tests": "error"
},
"settings": {
"import/resolver": {
"webpack": {
"config": "tools/config/webpack.config.js"
},
"node": {
"extensions": [
".js",
".jsx",
".ts",
".tsx"
]
}
}
},
"plugins": [
"jsx-a11y",
"react",
"react-hooks",
"no-only-tests",
"@typescript-eslint"
],
"overrides": [
{
"files": [
"*.ts",
"*.tsx"
],
"rules": {
"max-len": [
"error",
{
"code": 120,
"ignoreStrings": true,
"ignoreComments": true,
"tabWidth": 2,
"ignoreTemplateLiterals": true
}
],
"camelcase": [
"off"
], // handled by @typescript/camelcase
"semi": [
"off"
] // handled by @typescript/semi
}
}
]
}
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"${workspaceFolder}/**/${fileBasenameNoExtension}.js",

],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
Expand Down
4 changes: 4 additions & 0 deletions _answerTemplate/_.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
@function

*/
6 changes: 6 additions & 0 deletions _answerTemplate/_.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import something from './somewhere';

describe(': ', () => {
test('should return ', () => {
});
});
File renamed without changes.
29 changes: 29 additions & 0 deletions algos/arrays/easy/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
@function
Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

Example:

Given nums = [2, 7, 11, 15], target = 9,

Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
*/

export default function getAnswer({ nums, target }) {
const m = new Map();

for (let i = 0; i < nums.length; i++) {
if (m.has(target - nums[i])) {
if (m.get(target - nums[i]) === i) continue;
else {
return [m.get(target - nums[i]), i];
}
}
else {
m.set(nums[i], i);
}
}
}
12 changes: 12 additions & 0 deletions algos/arrays/easy/1.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import twoSum from './1';

describe('1: Two Sum', () => {
test('should add two numbers', () => {
let nums = [2,7,11];
let target = 9;
expect(twoSum({ nums, target })).toEqual([0, 1]);
nums = [4, 4, 5];
target = 8;
expect(twoSum({ nums, target })).toEqual([0, 1]);
});
});
33 changes: 33 additions & 0 deletions algos/arrays/easy/1313.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @function
We are given a list nums of integers representing a list compressed with run-length encoding.

Consider each adjacent pair of elements [freq, val] = [nums[2*i], nums[2*i+1]] (with i >= 0).
For each such pair, there are freq elements with value val concatenated in a sublist.
Concatenate all the sublists from left to right to generate the decompressed list.

Return the decompressed list.



Example 1:

Input: nums = [1,2,3,4]
Output: [2,4,4,4]
Explanation: The first pair [1,2] means we have freq = 1 and val = 2 so we generate the array [2].
The second pair [3,4] means we have freq = 3 and val = 4 so we generate [4,4,4].
At the end the concatenation [2] + [4,4,4] is [2,4,4,4].
Example 2:

Input: nums = [1,1,2,3]
Output: [1,3,3]
*/

export default function decompressRLEList(nums) {
let answer = [];
for (let i = 0; i < nums.length; i += 2) {
let [freq, val] = [nums[i], nums[i + 1]];
answer = answer.concat(new Array(freq).fill(val));
}
return answer;
}
10 changes: 10 additions & 0 deletions algos/arrays/easy/1313.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import decompressRLElist from './1313';

describe('1313: Decompress Run-Length Encoded List', () => {
test('should return decompressed list of nums', () => {
let nums = [1,2,3,4];
expect(decompressRLElist(nums)).toEqual([2, 4, 4, 4]);
nums = [1,1,2,3];
expect(decompressRLElist(nums)).toEqual([1, 3, 3]);
});
});
Loading