Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4e38ab5
fix: #758 optimised armstrongNumber code
developerr-ayush Sep 30, 2023
f8f0e2a
Merge branch 'master' of https://github.com/developerr-ayush/JavaScript
developerr-ayush Oct 1, 2023
184ae84
fix:#758 Average Median code optimised
developerr-ayush Oct 1, 2023
b8be2f9
feat: TwoSum function added with test cases
developerr-ayush Oct 1, 2023
882db43
revert code
developerr-ayush Oct 1, 2023
c58f28f
Fix: #758 used ternary operator to make code more optimised
developerr-ayush Oct 1, 2023
bdf8ed8
Feat: TwoSum function created with test cases
developerr-ayush Oct 2, 2023
8bde9b9
Feat: TwoSum function created with test cases
developerr-ayush Oct 2, 2023
a254b86
Merge branch 'TheAlgorithms:master' into master
developerr-ayush Oct 2, 2023
97e147c
Merge branch 'TheAlgorithms:master' into Feature-TwoSum-function
developerr-ayush Oct 2, 2023
01539b5
Merge pull request #1 from developerr-ayush/Feature-TwoSum-function
developerr-ayush Oct 2, 2023
5733b78
Resolved comments and changes requests
developerr-ayush Oct 3, 2023
abac923
Merge branch 'master' of https://github.com/developerr-ayush/JavaScript
developerr-ayush Oct 8, 2023
8b8d0c6
Feat: Format duration code added
developerr-ayush Oct 8, 2023
cbf18cf
duration format
developerr-ayush Oct 9, 2023
79b6adf
Merge branch 'master' of https://github.com/developerr-ayush/JavaScript
developerr-ayush Oct 21, 2023
fe40752
Feat: Created matrix search function with test cases
developerr-ayush Oct 21, 2023
bf5f741
deleted-old-file
developerr-ayush Oct 21, 2023
1a15dd4
Update BinaryCountSetBits.js
developerr-ayush Oct 21, 2023
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Maths/AutomorphicNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ export const isAutomorphic = (n) => {
n = Math.floor(n / 10)
n_sq = Math.floor(n_sq / 10)
}

return true
}
16 changes: 8 additions & 8 deletions Maths/test/AutomorphicNumber.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ describe('AutomorphicNumber', () => {
})

test.each([
{ n: -3 , expected: false },
{ n: -25 , expected: false },
{ n: -3, expected: false },
{ n: -25, expected: false }
])('should return false when n is negetive', ({ n, expected }) => {
expect(isAutomorphic(n)).toBe(false)
})

test.each([
{ n: 7 , expected: false },
{ n: 83 , expected: false },
{ n: 0 , expected: true },
{ n: 1 , expected: true },
{ n: 376 , expected: true },
{ n: 90625 , expected: true },
{ n: 7, expected: false },
{ n: 83, expected: false },
{ n: 0, expected: true },
{ n: 1, expected: true },
{ n: 376, expected: true },
{ n: 90625, expected: true }
])('should return $expected when n is $n', ({ n, expected }) => {
expect(isAutomorphic(n)).toBe(expected)
})
Expand Down
6 changes: 3 additions & 3 deletions Project-Euler/Problem006.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// https://projecteuler.net/problem=6

export const squareDifference = (num = 100) => {
let sumOfSquares = (num)*(num+1)*(2*num+1)/6
let sums = (num*(num+1))/2
let sumOfSquares = (num * (num + 1) * (2 * num + 1)) / 6
let sums = (num * (num + 1)) / 2

return sums ** 2 - sumOfSquares // difference of square of the total sum and sum of squares
}
2 changes: 1 addition & 1 deletion Search/InterpolationSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ export function interpolationSearch(arr, key) {
}

return -1
}
}
15 changes: 15 additions & 0 deletions Search/MatrixSearch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @param {T} key - The element to be found.
* @param {T[][]} matrix - The matrix in which the element should be found.
* @template T
* @returns {number[]} - An array containing the first found coordinates of the element.
*/
const MatrixSearch = (key, matrix) => {
for (let i = 0; i < matrix.length; i++) {
for (let j = 0; j < matrix[i].length; j++) {
if (matrix[i][j] === key) return [i, j] // Found the element, return its coordinates
}
}
return [-1, -1] // Element not found in the matrix
}
export { MatrixSearch }
51 changes: 51 additions & 0 deletions Search/test/MatrixSearch.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { MatrixSearch } from '../MatrixSearch' // Import the matrix search function

describe('MatrixSearchAlgorithm', () => {
const searchParam = [
[
5,
[
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
],
[1, 1]
],
[
5,
[
[1, 2, 3],
[4, 6, 7],
[8, 9, 10]
],
[-1, -1]
],
[42, [[42]], [0, 0]],
[
3,
[
[3, 5, 7],
[2, 4, 6],
[1, 8, 9]
],
[0, 0]
],
[
1,
[
[3, 5, 7],
[2, 4, 6],
[1, 8, 9]
],
[2, 0]
],
[5, [], [-1, -1]]
]

test.each(searchParam)(
'should find the element in the matrix',
(key, matrix, expected) => {
expect(MatrixSearch(key, matrix)).toEqual(expected)
}
)
})