Complying with JavaScript Standard Style (npx standard --fix).

This commit is contained in:
Eric Lavault
2021-10-11 15:49:24 +02:00
parent 87a3da7e37
commit df4a783b06
22 changed files with 28 additions and 42 deletions

View File

@ -18,7 +18,7 @@ const swap = (arr, i, j) => {
} }
const permutations = arr => { const permutations = arr => {
let P = [] const P = []
const permute = (arr, low, high) => { const permute = (arr, low, high) => {
if (low === high) { if (low === high) {
P.push([...arr]) P.push([...arr])

View File

@ -3,12 +3,12 @@ import { permutations } from '../GeneratePermutations'
describe('Permutations', () => { describe('Permutations', () => {
it('Permutations of [1, 2, 3]', () => { it('Permutations of [1, 2, 3]', () => {
expect(permutations([1, 2, 3])).toEqual([ expect(permutations([1, 2, 3])).toEqual([
[ 1, 2, 3 ], [1, 2, 3],
[ 1, 3, 2 ], [1, 3, 2],
[ 2, 1, 3 ], [2, 1, 3],
[ 2, 3, 1 ], [2, 3, 1],
[ 3, 1, 2 ], [3, 1, 2],
[ 3, 2, 1 ] [3, 2, 1]
]) ])
}) })
}) })

View File

@ -4,21 +4,20 @@ describe('OpenKnightTour', () => {
it('OpenKnightTour(5)', () => { it('OpenKnightTour(5)', () => {
const KT = new OpenKnightTour(5) const KT = new OpenKnightTour(5)
expect(KT.board).toEqual([ 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() KT.solve()
expect(KT.board).toEqual([ expect(KT.board).toEqual([
[ 19, 4, 15, 10, 25 ], [19, 4, 15, 10, 25],
[ 14, 9, 18, 5, 16 ], [14, 9, 18, 5, 16],
[ 1, 20, 3, 24, 11 ], [1, 20, 3, 24, 11],
[ 8, 13, 22, 17, 6 ], [8, 13, 22, 17, 6],
[ 21, 2, 7, 12, 23 ] [21, 2, 7, 12, 23]
]) ])
}) })
}) })

View File

@ -1,4 +1,4 @@
import {IsPowerOfTwo} from '../IsPowerOfTwo' import { IsPowerOfTwo } from '../IsPowerOfTwo'
test('Check if 0 is a power of 2 or not:', () => { test('Check if 0 is a power of 2 or not:', () => {
const res = IsPowerOfTwo(0) const res = IsPowerOfTwo(0)

View File

@ -73,7 +73,6 @@ function decrypt (message, key) {
export { encrypt, decrypt } export { encrypt, decrypt }
// > encrypt('Hello World!', 'code') // > encrypt('Hello World!', 'code')
// 'Jsopq Zstzg!' // 'Jsopq Zstzg!'

View File

@ -22,7 +22,6 @@ function XOR (str, key) {
export { XOR } export { XOR }
// Nb: Node REPL might not output the null char '\x00' (charcode 0) // Nb: Node REPL might not output the null char '\x00' (charcode 0)
// > XOR('test string', 32) // > XOR('test string', 32)

View File

@ -24,7 +24,6 @@ function hexToDecimal (hexNum) {
export { hexToInt, hexToDecimal } export { hexToInt, hexToDecimal }
// > hexToDecimal('5DE9A')) // > hexToDecimal('5DE9A'))
// 384666 // 384666

View File

@ -13,6 +13,5 @@ function hexStringToRGB (hexString) {
export { hexStringToRGB } export { hexStringToRGB }
// > hexStringToRGB('ffffff') // > hexStringToRGB('ffffff')
// { r: 255, g: 255, b: 255 } // { r: 255, g: 255, b: 255 }

View File

@ -40,8 +40,7 @@ const fahrenheitToRankine = (fahrenheit) => {
const kelvinToCelsius = (kelvin) => { const kelvinToCelsius = (kelvin) => {
// Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin // Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin
// Wikipedia reference: https://en.wikipedia.org/wiki/Celsius // Wikipedia reference: https://en.wikipedia.org/wiki/Celsius
return Math.round((kelvin) - 273.15) return Math.round((kelvin) - 273.15)
} }
const kelvinToFahrenheit = (kelvin) => { const kelvinToFahrenheit = (kelvin) => {
@ -53,7 +52,7 @@ const kelvinToFahrenheit = (kelvin) => {
const kelvinToRankine = (kelvin) => { const kelvinToRankine = (kelvin) => {
// Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin // Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin
// Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale // Wikipedia reference: https://en.wikipedia.org/wiki/Rankine_scale
return Math.round(( (kelvin) * 9 / 5)) return Math.round(((kelvin) * 9 / 5))
} }
const rankineToCelsius = (rankine) => { const rankineToCelsius = (rankine) => {

View File

@ -4,7 +4,7 @@ describe('MinPriorityQueue', () => {
const values = [5, 2, 4, 1, 7, 6, 3, 8] const values = [5, 2, 4, 1, 7, 6, 3, 8]
const capacity = values.length const capacity = values.length
const Queue = new MinPriorityQueue(capacity); const Queue = new MinPriorityQueue(capacity)
values.forEach(v => Queue.insert(v)) values.forEach(v => Queue.insert(v))
@ -12,7 +12,7 @@ describe('MinPriorityQueue', () => {
const mockFn = jest.fn() const mockFn = jest.fn()
Queue.print(mockFn) 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 expect(mockFn.mock.calls[0].length).toBe(1) // Expect one argument
const heap = mockFn.mock.calls[0][0] const heap = mockFn.mock.calls[0][0]

View File

@ -54,5 +54,4 @@ const Stack = (function () {
return Stack return Stack
}()) }())
export { Stack } export { Stack }

View File

@ -229,7 +229,7 @@ const AVLTree = (function () {
return true return true
} }
return _avl return _avl
}()); }())
/** /**
* A Code for Testing the AVLTree * A Code for Testing the AVLTree

View File

@ -116,6 +116,6 @@ Trie.prototype.findOccurences = function (word) {
// No such word exists // No such word exists
if (node === null) return 0 if (node === null) return 0
return node.count return node.count
}; }
export { Trie } export { Trie }

View File

@ -41,4 +41,3 @@ export { minCostPath }
// [2, 1, 3], // [2, 1, 3],
// [3, 2, 1] // [3, 2, 1]
// ]) // ])

View File

@ -40,7 +40,7 @@ const example = () => {
input.shift() input.shift()
const length = input.length const length = input.length
let output = [] const output = []
let i = 0 let i = 0
while (i < length) { while (i < length) {

View File

@ -9,4 +9,3 @@ function density (numberOfNodes, numberOfEdges, isDirected = false) {
} }
export { density } export { density }

View File

@ -45,4 +45,3 @@ export { FloydWarshall }
// [Infinity, Infinity, 1, 0] // [Infinity, Infinity, 1, 0]
// ] // ]
// ) // )

View File

@ -42,5 +42,3 @@ export const largestPalindromic = (digits) => {
} }
return NaN // returning not a number, if any such case arise return NaN // returning not a number, if any such case arise
} }

View File

@ -49,7 +49,7 @@ function binarySearchIterative (arr, x, low = 0, high = arr.length - 1) {
return -1 return -1
} }
export { binarySearchIterative, binarySearchRecursive} export { binarySearchIterative, binarySearchRecursive }
/* ---------------------------------- Test ---------------------------------- */ /* ---------------------------------- Test ---------------------------------- */

View File

@ -47,7 +47,7 @@ function exponentialSearch (arr, length, value) {
return binarySearch(arr, value, i / 2, Math.min(i, length)) 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 arr = [2, 3, 4, 10, 40, 65, 78, 100]
// const value = 78 // const value = 78

View File

@ -8,8 +8,7 @@ function SearchArray (searchNum, ar, output = v => console.log(v)) {
const position = Search(ar, searchNum) const position = Search(ar, searchNum)
if (position !== -1) { if (position !== -1) {
output('The element was found at ' + (position + 1)) output('The element was found at ' + (position + 1))
} } else {
else {
output('The element not found') output('The element not found')
} }
} }

View File

@ -25,4 +25,3 @@ export function gnomeSort (items) {
// const ar = [5, 6, 7, 8, 1, 2, 12, 14] // const ar = [5, 6, 7, 8, 1, 2, 12, 14]
// gnomeSort(ar) // gnomeSort(ar)