Skip to content

Commit 57178b3

Browse files
committed
FirstProblem Added
1 parent 56e0981 commit 57178b3

14 files changed

+4309
-1
lines changed

.eslintrc.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
"env": {
3+
"browser": true,
4+
"commonjs": true,
5+
"node":true,
6+
"es2021": true,
7+
"jest": true,
8+
},
9+
"extends": "eslint:recommended",
10+
"overrides": [
11+
],
12+
"parserOptions": {
13+
"ecmaVersion": "latest"
14+
},
15+
"rules": {
16+
},
17+
18+
}

.github/workflows/ci.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# .github/workflows/ci.yml
2+
3+
# Continuous Integration (CI) Workflow
4+
name: ci
5+
6+
# This workflow will run whenever we push commits to the `main` branch, or
7+
# whenever there's a pull request to the `main` branch. See:
8+
# https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#on
9+
on:
10+
pull_request:
11+
branches:
12+
- main
13+
push:
14+
branches:
15+
- main
16+
17+
jobs:
18+
lint:
19+
# Give your job a name that will show up in the GitHub Actions web UI
20+
name: ESLint
21+
# We'll run this on a Linux (Ubuntu) VM, since we'll deploy on Linux too.
22+
runs-on: ubuntu-latest
23+
# We run these steps one after the other, and if any fail, we stop the process
24+
steps:
25+
# https://github.com/actions/checkout
26+
- name: Check out code
27+
uses: actions/checkout@v3
28+
29+
# https://github.com/actions/setup-node
30+
- name: Setup node
31+
uses: actions/setup-node@v3
32+
with:
33+
# Use node LTS version 18 - https://github.com/actions/setup-node#supported-version-syntax
34+
node-version: '18'
35+
# Cache npm dependencies so they don't have to be downloaded next time - https://github.com/actions/setup-node#caching-packages-dependencies
36+
cache: 'npm'
37+
38+
- name: Install node dependencies
39+
# Use `ci` vs. `install`, see https://docs.npmjs.com/cli/v8/commands/npm-ci
40+
run: npm ci
41+
42+
- name: Run ESLint
43+
run: npm run lint
44+
unit-tests:
45+
name: Unit Tests
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Check out code
49+
uses: actions/checkout@v3
50+
51+
- name: Setup node
52+
uses: actions/setup-node@v3
53+
with:
54+
node-version: '18'
55+
cache: 'npm'
56+
57+
- name: Install node dependencies and run Tests
58+
run: |
59+
npm install
60+
npm run testIbrahimsSolution
61+

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#All Node Modules
2+
/node_modules/
3+
4+
#prettierFiles
5+
/.prettierignore

.prettierrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"arrowParens": "always",
3+
"bracketSpacing": true,
4+
"embeddedLanguageFormatting": "auto",
5+
"endOfLine": "lf",
6+
"insertPragma": false,
7+
"proseWrap": "preserve",
8+
"requirePragma": false,
9+
"singleQuote": true,
10+
"tabWidth": 2,
11+
"trailingComma": "es5",
12+
"useTabs": false,
13+
"printWidth": 100
14+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number[]}
4+
*/
5+
module.exports = function (nums) {
6+
let rtrn = [...nums];
7+
for (
8+
let i = 0;
9+
i < nums.length;
10+
i++ // iterator between 0 .. nums.length
11+
)
12+
for (
13+
let j = i - 1;
14+
j >= 0;
15+
j-- // iterate between i .. 0
16+
)
17+
rtrn[i] += nums[j]; // add nums[j] to
18+
19+
return rtrn;
20+
};
21+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { describe } = require('node:test');
2+
const RunningSums = require('./MySolutionToRunningSums');
3+
4+
module.exports = () => {
5+
describe('Testing Running Sums', () => {
6+
// Write a test for calling createErrorResponse()
7+
test('Test 1: [1,2,3,4]', () => {
8+
expect(RunningSums([1, 2, 3, 4])).toEqual([1, 3, 6, 10]);
9+
});
10+
11+
test('Test 2: [1,1,1,1,1]', () => {
12+
expect(RunningSums([1, 1, 1, 1, 1])).toEqual([1, 2, 3, 4, 5]);
13+
});
14+
15+
test('Test 2: [3,1,2,10,1]', () => {
16+
expect(RunningSums([3, 1, 2, 10, 1])).toEqual([3, 4, 6, 16, 17]);
17+
});
18+
});
19+
};

Problems/1-RunningSums/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# [Running Sum of 1-D Array](https://leetcode.com/problems/running-sum-of-1d-array/?envType=study-plan&id=level-1) (Leetcode)
2+
3+
Given an array `nums`. We define a running sum of an array as:
4+
5+
> `runningSum[i] = sum(nums[0]…nums[i])`.
6+
7+
Return the running sum of nums.
8+
9+
10+
11+
Example 1:
12+
13+
> Input: `nums = [1,2,3,4]`
14+
>
15+
> Output: `[1,3,6,10]`
16+
>
17+
> **Explanation**: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].
18+
19+
Example 2:
20+
21+
> Input: nums = [1,1,1,1,1]
22+
>
23+
> Output: [1,2,3,4,5]
24+
>
25+
> **Explanation**: Running sum is obtained as follows: [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1].
26+
27+
Example 3:
28+
29+
> Input: nums = [3,1,2,10,1]
30+
>
31+
> Output: [3,4,6,16,17]
32+
33+
34+
**Constraints:**
35+
- 1 <= nums.length <= 1000
36+
- -10^6 <= nums[i] <= 10^6

Problems/1-RunningSums/RunningSums.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number[]}
4+
*/
5+
module.exports = function (nums) {
6+
return nums;
7+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { describe } = require('node:test');
2+
const RunningSums = require('./RunningSums');
3+
4+
describe('Testing Running Sums', () => {
5+
// Write a test for calling createErrorResponse()
6+
test('Test 1: [1,2,3,4]', () => {
7+
expect(RunningSums([1, 2, 3, 4])).toEqual([1, 3, 6, 10]);
8+
});
9+
10+
test('Test 2: [1,1,1,1,1]', () => {
11+
expect(RunningSums([1,1,1,1,1])).toEqual([1,2,3,4,5]);
12+
});
13+
14+
test('Test 2: [3,1,2,10,1]', () => {
15+
expect(RunningSums([3,1,2,10,1])).toEqual([3,4,6,16,17]);
16+
});
17+
});

README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,46 @@
11
# DataStructures-Algorithms
2-
Showcasing my experience solving popular LeetCode problems
2+
Showcasing my experience solving popular LeetCode problems, along with templates to how to solving questions on your own that run through Unit Tests to check for completion.
3+
4+
## Table of Contents
5+
[Recommendations for development:](https://https://github.com/0bro/DataStructures-Algorithms#recommendations-for-development)
6+
7+
8+
9+
### **Recommendations** for development:
10+
11+
Install VSCode extention `TODO Highlight` to visualize and query all flags. The flags are:
12+
13+
- `TODO:` A Task that is required to be done within this function, block, or line
14+
- `BUG:` A definition of Bug that is occuring originating from this block/area
15+
- `TOFIX:` Instructions on how to fix a problem that is code breaking
16+
- `ISSUE:` An Issue that isn't a bug, and also doesn't break the runtime.
17+
- `IDEA:` A proposal for an idea to how we can either fix a `BUG:`, `ISSUE:`, or to change the codebase.
18+
- `TEST:` Requires testing to complete test coverage
19+
20+
To add these keywords, follow these steps to install `TODO Highlight`:
21+
22+
1. Find `TODO Highlight` in EXTENTIONS: MARKETPLACE
23+
2. Install and wait for Install
24+
3. After Installation, click the gear icon that appears near where the install button one.
25+
4. Choose "Extension Settings"
26+
5. Find any option and Choose the "<ins>Edit in Settings.json</ins>"
27+
6. Find the `todohighlight.keywords` object and add the following code:
28+
29+
```json
30+
"todohighlight.keywords": [
31+
{ "text": "TOFIX:", "backgroundColor": "purple", "color": "White" },
32+
{ "text": "BUG:", "backgroundColor": "teal", "color": "White" },
33+
{ "text": "ISSUE:", "backgroundColor": "red", "color": "White" },
34+
{ "text": "IDEA:", "backgroundColor": "blue", "color": "White" },
35+
{ "text": "TEST:", "backgroundColor": "green", "color": "White" }
36+
]
37+
```
38+
39+
## Scripts
40+
41+
Scripts that are supported by this project use Pino for logging and not are:
42+
43+
- `npm run lint` : tests the server and it's dependancies for syntax and problems using ESLint
44+
- `start` : Starts server with surface level `info` logs
45+
- `dev` : Starts server with `debug` logs
46+
- `debug` : Start server and watch for breakpoints

jest.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// jest.config.js
2+
3+
// Get the full path to our env.jest file
4+
// const path = require('path');
5+
// const envFile = path.join(__dirname, 'env.jest');
6+
7+
8+
// Read the environment variables we use for Jest from our env.jest file
9+
// require('dotenv').config({ path: envFile });
10+
11+
// Set our Jest options, see https://jestjs.io/docs/configuration
12+
module.exports = {
13+
verbose: true,
14+
testTimeout: 5000,
15+
};

0 commit comments

Comments
 (0)