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: TheAlgorithms/JavaScript
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: nikgautamgithub/JavaScript
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 7 commits
  • 2 files changed
  • 1 contributor

Commits on Oct 3, 2023

  1. Verified

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

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

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

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

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

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

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    bc88107 View commit details
Showing with 26 additions and 0 deletions.
  1. +17 −0 Bit-Manipulation/MinMaxElement.js
  2. +9 −0 Bit-Manipulation/test/MinMaxElement.test.js
17 changes: 17 additions & 0 deletions Bit-Manipulation/MinMaxElement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @author : nikgautamgithub
*
* Find max or min element using bit operators.
* @param {number} x - The input number to compare.
* @param {number} y - The input number to compare.
* @returns Min/Max Element
*
* @example
* const maxi = max(5,3) // Returns max number i.e. 5
* const mini = min(5,3); // Returns min number i.e. 3
*/
const max = (x, y) => x ^ ((x ^ y) & -(x < y ? 1 : 0))

const min = (x, y) => y ^ ((x ^ y) & -(x < y ? 1 : 0))

export { min, max }
9 changes: 9 additions & 0 deletions Bit-Manipulation/test/MinMaxElement.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { min, max } from '../minMaxElement'

test('Find max element from 5 and 3 :', () => {
expect(max(5, 3)).toBe(5)
})

test('Find min element from 5 and 3 :', () => {
expect(min(5, 3)).toBe(3)
})