Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ashishprasad2163/problem-solving-javascript
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: knaxus/problem-solving-javascript
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 15 commits
  • 7 files changed
  • 5 contributors

Commits on Dec 2, 2022

  1. build(deps): bump decode-uri-component from 0.2.0 to 0.2.2

    Bumps [decode-uri-component](https://github.com/SamVerschueren/decode-uri-component) from 0.2.0 to 0.2.2.
    - [Release notes](https://github.com/SamVerschueren/decode-uri-component/releases)
    - [Commits](SamVerschueren/decode-uri-component@v0.2.0...v0.2.2)
    
    ---
    updated-dependencies:
    - dependency-name: decode-uri-component
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Dec 2, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b8ffce9 View commit details

Commits on Dec 7, 2022

  1. Created some add/remove test cases

    Created test cases for add and remove
    maxMyers13 authored Dec 7, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c016ce4 View commit details

Commits on Jan 9, 2023

  1. build(deps): bump json5 from 1.0.1 to 1.0.2

    Bumps [json5](https://github.com/json5/json5) from 1.0.1 to 1.0.2.
    - [Release notes](https://github.com/json5/json5/releases)
    - [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md)
    - [Commits](json5/json5@v1.0.1...v1.0.2)
    
    ---
    updated-dependencies:
    - dependency-name: json5
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Jan 9, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b4d905d View commit details

Commits on Jan 10, 2023

  1. Merge pull request knaxus#206 from knaxus/dependabot/npm_and_yarn/jso…

    …n5-1.0.2
    
    build(deps): bump json5 from 1.0.1 to 1.0.2
    ashokdey authored Jan 10, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    bde32a5 View commit details
  2. Merge pull request knaxus#204 from knaxus/dependabot/npm_and_yarn/dec…

    …ode-uri-component-0.2.2
    
    build(deps): bump decode-uri-component from 0.2.0 to 0.2.2
    ashokdey authored Jan 10, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2173ed5 View commit details
  3. Merge pull request knaxus#205 from maxMyers13/patch-1

    Created some add/remove test cases
    ashokdey authored Jan 10, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    84b229a View commit details
  4. Update README.md

    ashokdey authored Jan 10, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f00164b View commit details
  5. Create node.js.yml

    ashokdey authored Jan 10, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    56fb83e View commit details

Commits on Apr 21, 2023

  1. feat: add new file

    Ahtaxam committed Apr 21, 2023
    Copy the full SHA
    782e1ee View commit details
  2. Copy the full SHA
    fc2218f View commit details
  3. feat: add 3sum problem

    Ahtaxam committed Apr 21, 2023
    Copy the full SHA
    84b480e View commit details

Commits on Jun 18, 2023

  1. refactor: made changes

    Ahtaxam committed Jun 18, 2023
    Copy the full SHA
    75a9df6 View commit details
  2. Merge pull request knaxus#207 from Ahtaxam/master

    Add 3-sum problem with improvement issue knaxus#208
    ashokdey authored Jun 18, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d62e62c View commit details

Commits on May 5, 2024

  1. Update README.md

    Fix some grammar nits and make tweaks to the same.
    MartinLBeacham authored May 5, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    a31ab16 View commit details

Commits on Jan 19, 2025

  1. Merge pull request knaxus#214 from MartinLBeacham/patch-1

    Update README.md
    ashokdey authored Jan 19, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    5bebc4b View commit details
Showing with 153 additions and 22 deletions.
  1. +31 −0 .github/workflows/node.js.yml
  2. +2 −3 README.md
  3. +1 −1 TOC.md
  4. +18 −18 package-lock.json
  5. +43 −0 src/_DataStructures_/Set/setTest.js
  6. +39 −0 src/_Problems_/3Sum/3sum.js
  7. +19 −0 src/_Problems_/3Sum/3sum.test.js
31 changes: 31 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@

# Problem Solving using Javascript

[![Open Source Love](https://badges.frapsoft.com/os/v2/open-source.svg?v=103)](https://github.com/vinitshahdeo/HacktoberFest)
[![Build Status](https://travis-ci.org/knaxus/problem-solving-javascript.svg?branch=master)](https://travis-ci.org/knaxus/problem-solving-javascript)
[![Coverage Status](https://coveralls.io/repos/github/knaxus/problem-solving-javascript/badge.svg?branch=master)](https://coveralls.io/github/knaxus/problem-solving-javascript?branch=master)
![GitHub stars](https://img.shields.io/github/stars/knaxus/problem-solving-javascript)
@@ -41,6 +40,6 @@ Find the detailed contents and problem list here: [Table Of Contents](TOC.md)

## Contribution Guide

It's great to know that you want to contribute to this repo. Thanks for taking interest. please find the [guide here](https://github.com/knaxus/problem-solving-javascript/blob/master/CONTRIBUTING.md)
It's great to know that you want to contribute to this repo. Thanks for taking interest. Please find the [guide here](https://github.com/knaxus/problem-solving-javascript/blob/master/CONTRIBUTING.md)

Keep an eye on this guide, it's subjected to change frequently.
Keep an eye on this guide. It's subject to frequent change.
2 changes: 1 addition & 1 deletion TOC.md
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@
- [Next Greater for Every Element in an Array](src/_Problems_/next-greater-element)
- [Compose Largest Number](src/_Problems_/compose-largest-number)
- [Rotate Image](src/_Problems_/rotate-image)

- [3 Sum](src/_Problems_/3Sum/)
### Searching

- [Binary Search](src/_Searching_/BinarySearch)
36 changes: 18 additions & 18 deletions package-lock.json

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

43 changes: 43 additions & 0 deletions src/_DataStructures_/Set/setTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const letters = require('./index');

describe('Data Structure : Set', () => {


it('X Set should be a Class', () => {
expect(typeof XSet.prototype.constructor).toEqual('function');
});

describe('Creation of Set', () => {

it('Should create a new Set with no elements', () => {
letters = new XSet();
expect(letters === 0);
});

it('Should add letter A', () => {
letters.add('a');
expect(letters.has('a');
});

it('Should add letter B', () => {
letters.add('b');
expect(letters.has('b');
});

it('Should add letter C', () => {
letters.add('c');
expect(letters.has('c');
});

it('Should remove letter A', () => {
letters.remove('a');
expect(!letters.has('a');
});

it('Should remove letter B', () => {
letters.remove('b');
expect(!letters.has('b');
});


});
39 changes: 39 additions & 0 deletions src/_Problems_/3Sum/3sum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const threeSum = function(nums) {
// sort the array
nums = nums.sort((a, b) => a - b);

let result = [];
// iterate through the array and use two pointers to find the sum
for (let i = 0; i < nums.length; ++i) {
let left = i + 1;
let right = nums.length - 1;
while (left < right) {
let sum = nums[i] + nums[left] + nums[right];
if (sum == 0) {
result.push([nums[i], nums[left], nums[right]]);
left++;
right--;
}
else if (sum < 0) {
left++;
}
else {
right--;
}
}
// skip duplicates
while (i < nums.length - 1 && nums[i] == nums[i + 1]) {
i++;
}
}

// initialize set to remove duplicate
const set = new Set(result.map(JSON.stringify));
// final output array
output = (new Array(...set).map(JSON.parse));
return output;
};


module.exports = threeSum;

19 changes: 19 additions & 0 deletions src/_Problems_/3Sum/3sum.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const threeSum = require("./3sum");

describe("threeSum", () => {
it("Should return [[-1, -1, 2], [-1, 0, 1]]", () => {
expect(threeSum([-1, 0, 1, 2, -1, -4])).toEqual([
[-1, -1, 2],
[-1, 0, 1],
]);
});

it("Should return [[0, 0, 0]]", () => {
expect(threeSum([0, 0, 0])).toEqual([[0, 0, 0]]);
});

it("Should return [[-1, -1, 2]]", () => {
expect(threeSum([-1, 2, -1, -4])).toEqual([[-1, -1, 2]]);
});

});