Skip to content

Commit

Permalink
Merge pull request #11 from james-gates-0212/10-bracket-combinations
Browse files Browse the repository at this point in the history
10 bracket combinations
  • Loading branch information
james-gates-0212 authored Mar 27, 2024
2 parents bf1cdfc + 6803257 commit 971e1ff
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .github/workflows/auto-assign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Auto Assign
on:
issues:
types: [opened]
pull_request:
types: [opened]
jobs:
run:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: 'Auto-assign issue'
uses: pozil/auto-assign-issue@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
assignees: james-gates-0212
numOfAssignee: 1
84 changes: 84 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: '43 9 * * 6'

jobs:
analyze:
name: Analyze
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners
# Consider using larger runners for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
# required for all workflows
security-events: write

# only required for workflows in private repositories
actions: read
contents: read

strategy:
fail-fast: false
matrix:
language: [ 'javascript-typescript' ]
# CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ]
# Use only 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
11 changes: 11 additions & 0 deletions .github/workflows/proof-html.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Proof HTML
on:
push:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: anishathalye/proof-html@v1.1.0
with:
directory: ./
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# 📓JavaScript Assessments

Here are JavaScript Assessments. I hope it could helps you and your works.

## 🔖Repository Status

[![Auto Assign](https://github.com/james-gates-0212/js-assessments/actions/workflows/auto-assign.yml/badge.svg)](https://github.com/james-gates-0212/js-assessments/actions/workflows/auto-assign.yml)
[![CodeQL](https://github.com/james-gates-0212/js-assessments/actions/workflows/codeql.yml/badge.svg)](https://github.com/james-gates-0212/js-assessments/actions/workflows/codeql.yml)
[![Proof HTML](https://github.com/james-gates-0212/js-assessments/actions/workflows/proof-html.yml/badge.svg)](https://github.com/james-gates-0212/js-assessments/actions/workflows/proof-html.yml)

## Table of contents

- [Bracket Combinations](bracket-combinations)
- [Calculate the sum of the numbers in a nested array](calculate-the-sum-of-the-numbers-in-a-nested-array)
- [Convert string to group](convert-string-to-group)
- [Delete Overlapping Intervals](delete-overlapping-intervals)
Expand Down Expand Up @@ -63,11 +74,14 @@ e.g.
```bash
add
adopt
apply
build
chore
config
docs
feat
fix
init
refactor
remove
style
Expand Down
16 changes: 16 additions & 0 deletions bracket-combinations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Bracket Combinations

Have the function `BracketCombinations(num)` read `num` which will be an integer greater than or equal to zero, and return the number of valid combinations that can be formed with num pairs of parentheses. For example, if the input is 3, then the possible combinations of 3 pairs of parenthesis, namely: `()()()`, are `()()()`, `()(())`, `(())()`, `((()))`, and `(()())`. There are 5 total combinations when the input is 3, so your program should return 5.

## Examples

```javascript
BracketCombinations(2); // should == 2
BracketCombinations(3); // should == 5
```

## Execute

```bash
node solution.js
```
27 changes: 27 additions & 0 deletions bracket-combinations/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function BracketCombinations(num) {
if (num === 0) {
return 1;
}
// By Doing sum search i found a formula that can achieve what this problem want
// called Catalan number (Catalan Formula)
// where catalan formula is ==> (2n!) / (n+1)! n!

// first i will calculate the factorial of the num
let factorial = (n) => {
let k = 1;
for (var i = n; i >= 2; i--) {
k *= i;
}
return k;
};

// formula going down
const result = factorial(2 * num) / (factorial(num + 1) * factorial(num));
return result;
}

(() => {
[2, 3, 5, 8].forEach((num) => {
console.log(JSON.stringify(num), '==', BracketCombinations(num));
});
})();
16 changes: 15 additions & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,21 @@ const config = {
'type-enum': [
2,
'always',
['add', 'adopt', 'build', 'chore', 'docs', 'feat', 'fix', 'refactor', 'remove', 'style'],
[
'add',
'adopt',
'apply',
'build',
'chore',
'config',
'docs',
'feat',
'fix',
'init',
'refactor',
'remove',
'style',
],
],
},
};
Expand Down

0 comments on commit 971e1ff

Please # to comment.