mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-04 07:29:47 +08:00
Complying with JavaScript Standard Style (npx standard --fix).
This commit is contained in:
@ -18,7 +18,7 @@ const swap = (arr, i, j) => {
|
||||
}
|
||||
|
||||
const permutations = arr => {
|
||||
let P = []
|
||||
const P = []
|
||||
const permute = (arr, low, high) => {
|
||||
if (low === high) {
|
||||
P.push([...arr])
|
||||
|
@ -3,12 +3,12 @@ import { permutations } from '../GeneratePermutations'
|
||||
describe('Permutations', () => {
|
||||
it('Permutations of [1, 2, 3]', () => {
|
||||
expect(permutations([1, 2, 3])).toEqual([
|
||||
[ 1, 2, 3 ],
|
||||
[ 1, 3, 2 ],
|
||||
[ 2, 1, 3 ],
|
||||
[ 2, 3, 1 ],
|
||||
[ 3, 1, 2 ],
|
||||
[ 3, 2, 1 ]
|
||||
[1, 2, 3],
|
||||
[1, 3, 2],
|
||||
[2, 1, 3],
|
||||
[2, 3, 1],
|
||||
[3, 1, 2],
|
||||
[3, 2, 1]
|
||||
])
|
||||
})
|
||||
})
|
||||
|
@ -4,21 +4,20 @@ describe('OpenKnightTour', () => {
|
||||
it('OpenKnightTour(5)', () => {
|
||||
const KT = new OpenKnightTour(5)
|
||||
expect(KT.board).toEqual([
|
||||
[ 0, 0, 0, 0, 0 ],
|
||||
[ 0, 0, 0, 0, 0 ],
|
||||
[ 0, 0, 0, 0, 0 ],
|
||||
[ 0, 0, 0, 0, 0 ],
|
||||
[ 0, 0, 0, 0, 0 ]
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0]
|
||||
])
|
||||
|
||||
KT.solve()
|
||||
expect(KT.board).toEqual([
|
||||
[ 19, 4, 15, 10, 25 ],
|
||||
[ 14, 9, 18, 5, 16 ],
|
||||
[ 1, 20, 3, 24, 11 ],
|
||||
[ 8, 13, 22, 17, 6 ],
|
||||
[ 21, 2, 7, 12, 23 ]
|
||||
[19, 4, 15, 10, 25],
|
||||
[14, 9, 18, 5, 16],
|
||||
[1, 20, 3, 24, 11],
|
||||
[8, 13, 22, 17, 6],
|
||||
[21, 2, 7, 12, 23]
|
||||
])
|
||||
})
|
||||
|
||||
})
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {IsPowerOfTwo} from '../IsPowerOfTwo'
|
||||
import { IsPowerOfTwo } from '../IsPowerOfTwo'
|
||||
|
||||
test('Check if 0 is a power of 2 or not:', () => {
|
||||
const res = IsPowerOfTwo(0)
|
||||
|
@ -73,7 +73,6 @@ function decrypt (message, key) {
|
||||
|
||||
export { encrypt, decrypt }
|
||||
|
||||
|
||||
// > encrypt('Hello World!', 'code')
|
||||
// 'Jsopq Zstzg!'
|
||||
|
||||
|
@ -22,7 +22,6 @@ function XOR (str, key) {
|
||||
|
||||
export { XOR }
|
||||
|
||||
|
||||
// Nb: Node REPL might not output the null char '\x00' (charcode 0)
|
||||
|
||||
// > XOR('test string', 32)
|
||||
|
@ -24,7 +24,6 @@ function hexToDecimal (hexNum) {
|
||||
|
||||
export { hexToInt, hexToDecimal }
|
||||
|
||||
|
||||
// > hexToDecimal('5DE9A'))
|
||||
// 384666
|
||||
|
||||
|
@ -13,6 +13,5 @@ function hexStringToRGB (hexString) {
|
||||
|
||||
export { hexStringToRGB }
|
||||
|
||||
|
||||
// > hexStringToRGB('ffffff')
|
||||
// { r: 255, g: 255, b: 255 }
|
||||
|
@ -40,8 +40,7 @@ const fahrenheitToRankine = (fahrenheit) => {
|
||||
const kelvinToCelsius = (kelvin) => {
|
||||
// Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin
|
||||
// Wikipedia reference: https://en.wikipedia.org/wiki/Celsius
|
||||
return Math.round((kelvin) - 273.15)
|
||||
|
||||
return Math.round((kelvin) - 273.15)
|
||||
}
|
||||
|
||||
const kelvinToFahrenheit = (kelvin) => {
|
||||
@ -53,7 +52,7 @@ const kelvinToFahrenheit = (kelvin) => {
|
||||
const kelvinToRankine = (kelvin) => {
|
||||
// Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin
|
||||
// Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale
|
||||
return Math.round(( (kelvin) * 9 / 5))
|
||||
return Math.round(((kelvin) * 9 / 5))
|
||||
}
|
||||
|
||||
const rankineToCelsius = (rankine) => {
|
||||
|
@ -4,7 +4,7 @@ describe('MinPriorityQueue', () => {
|
||||
const values = [5, 2, 4, 1, 7, 6, 3, 8]
|
||||
const capacity = values.length
|
||||
|
||||
const Queue = new MinPriorityQueue(capacity);
|
||||
const Queue = new MinPriorityQueue(capacity)
|
||||
|
||||
values.forEach(v => Queue.insert(v))
|
||||
|
||||
@ -12,7 +12,7 @@ describe('MinPriorityQueue', () => {
|
||||
const mockFn = jest.fn()
|
||||
Queue.print(mockFn)
|
||||
|
||||
expect(mockFn.mock.calls.length).toBe(1) // Expect one call
|
||||
expect(mockFn.mock.calls.length).toBe(1) // Expect one call
|
||||
expect(mockFn.mock.calls[0].length).toBe(1) // Expect one argument
|
||||
|
||||
const heap = mockFn.mock.calls[0][0]
|
||||
|
@ -54,5 +54,4 @@ const Stack = (function () {
|
||||
return Stack
|
||||
}())
|
||||
|
||||
|
||||
export { Stack }
|
||||
|
@ -229,7 +229,7 @@ const AVLTree = (function () {
|
||||
return true
|
||||
}
|
||||
return _avl
|
||||
}());
|
||||
}())
|
||||
|
||||
/**
|
||||
* A Code for Testing the AVLTree
|
||||
|
@ -116,6 +116,6 @@ Trie.prototype.findOccurences = function (word) {
|
||||
// No such word exists
|
||||
if (node === null) return 0
|
||||
return node.count
|
||||
};
|
||||
}
|
||||
|
||||
export { Trie }
|
||||
|
@ -41,4 +41,3 @@ export { minCostPath }
|
||||
// [2, 1, 3],
|
||||
// [3, 2, 1]
|
||||
// ])
|
||||
|
||||
|
@ -40,7 +40,7 @@ const example = () => {
|
||||
input.shift()
|
||||
const length = input.length
|
||||
|
||||
let output = []
|
||||
const output = []
|
||||
|
||||
let i = 0
|
||||
while (i < length) {
|
||||
|
@ -9,4 +9,3 @@ function density (numberOfNodes, numberOfEdges, isDirected = false) {
|
||||
}
|
||||
|
||||
export { density }
|
||||
|
||||
|
@ -45,4 +45,3 @@ export { FloydWarshall }
|
||||
// [Infinity, Infinity, 1, 0]
|
||||
// ]
|
||||
// )
|
||||
|
||||
|
@ -42,5 +42,3 @@ export const largestPalindromic = (digits) => {
|
||||
}
|
||||
return NaN // returning not a number, if any such case arise
|
||||
}
|
||||
|
||||
|
||||
|
@ -49,7 +49,7 @@ function binarySearchIterative (arr, x, low = 0, high = arr.length - 1) {
|
||||
return -1
|
||||
}
|
||||
|
||||
export { binarySearchIterative, binarySearchRecursive}
|
||||
export { binarySearchIterative, binarySearchRecursive }
|
||||
|
||||
/* ---------------------------------- Test ---------------------------------- */
|
||||
|
||||
|
@ -47,7 +47,7 @@ function exponentialSearch (arr, length, value) {
|
||||
return binarySearch(arr, value, i / 2, Math.min(i, length))
|
||||
}
|
||||
|
||||
export { binarySearch, exponentialSearch}
|
||||
export { binarySearch, exponentialSearch }
|
||||
|
||||
// const arr = [2, 3, 4, 10, 40, 65, 78, 100]
|
||||
// const value = 78
|
||||
|
@ -8,8 +8,7 @@ function SearchArray (searchNum, ar, output = v => console.log(v)) {
|
||||
const position = Search(ar, searchNum)
|
||||
if (position !== -1) {
|
||||
output('The element was found at ' + (position + 1))
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
output('The element not found')
|
||||
}
|
||||
}
|
||||
|
@ -25,4 +25,3 @@ export function gnomeSort (items) {
|
||||
|
||||
// const ar = [5, 6, 7, 8, 1, 2, 12, 14]
|
||||
// gnomeSort(ar)
|
||||
|
||||
|
Reference in New Issue
Block a user