mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 00:01:37 +08:00
Comply with ESM syntax.
This commit is contained in:
@ -38,4 +38,4 @@ const DateDayDifference = (date1, date2) => {
|
||||
|
||||
// Example : DateDayDifference('17/08/2002', '10/10/2020') => 6630
|
||||
|
||||
module.exports = DateDayDifference
|
||||
export { DateDayDifference }
|
||||
|
@ -61,4 +61,4 @@ const DateToDay = (date) => {
|
||||
|
||||
// Example : DateToDay("18/12/2020") => Friday
|
||||
|
||||
module.exports = DateToDay
|
||||
export { DateToDay }
|
||||
|
@ -32,4 +32,4 @@ const LowerCaseConversion = (inputString) => {
|
||||
return newString.join('')
|
||||
}
|
||||
|
||||
module.exports = LowerCaseConversion
|
||||
export { LowerCaseConversion }
|
||||
|
@ -32,4 +32,4 @@ const RailwayTimeConversion = (timeString) => {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RailwayTimeConversion
|
||||
export { RailwayTimeConversion }
|
||||
|
@ -234,39 +234,39 @@ const AVLTree = (function () {
|
||||
/**
|
||||
* A Code for Testing the AVLTree
|
||||
*/
|
||||
(function test () {
|
||||
const newAVL = new AVLTree()
|
||||
const size = Math.floor(Math.random() * 1000000)
|
||||
let uniques = 0
|
||||
let i, temp, j
|
||||
const array = []
|
||||
for (i = 0; i < size; i++) {
|
||||
temp = Math.floor(Math.random() * Number.MAX_VALUE)
|
||||
if (newAVL.add(temp)) {
|
||||
uniques++
|
||||
array.push(temp)
|
||||
}
|
||||
}
|
||||
if (newAVL.size !== uniques) {
|
||||
throw new Error('elements not inserted properly')
|
||||
}
|
||||
const findTestSize = Math.floor(Math.random() * uniques)
|
||||
for (i = 0; i < findTestSize; i++) {
|
||||
j = Math.floor(Math.random() * uniques)
|
||||
if (!newAVL.find(array[j])) {
|
||||
throw new Error('inserted elements not found')
|
||||
}
|
||||
}
|
||||
const deleteTestSize = Math.floor(uniques * Math.random())
|
||||
for (i = 0; i < deleteTestSize; i++) {
|
||||
j = Math.floor(Math.random() * uniques)
|
||||
temp = array[j]
|
||||
if (newAVL.find(temp)) {
|
||||
if (!newAVL.remove(temp)) {
|
||||
throw new Error('delete not working properly')
|
||||
}
|
||||
}
|
||||
}
|
||||
})()
|
||||
// (function test () {
|
||||
// const newAVL = new AVLTree()
|
||||
// const size = Math.floor(Math.random() * 1000000)
|
||||
// let uniques = 0
|
||||
// let i, temp, j
|
||||
// const array = []
|
||||
// for (i = 0; i < size; i++) {
|
||||
// temp = Math.floor(Math.random() * Number.MAX_VALUE)
|
||||
// if (newAVL.add(temp)) {
|
||||
// uniques++
|
||||
// array.push(temp)
|
||||
// }
|
||||
// }
|
||||
// if (newAVL.size !== uniques) {
|
||||
// throw new Error('elements not inserted properly')
|
||||
// }
|
||||
// const findTestSize = Math.floor(Math.random() * uniques)
|
||||
// for (i = 0; i < findTestSize; i++) {
|
||||
// j = Math.floor(Math.random() * uniques)
|
||||
// if (!newAVL.find(array[j])) {
|
||||
// throw new Error('inserted elements not found')
|
||||
// }
|
||||
// }
|
||||
// const deleteTestSize = Math.floor(uniques * Math.random())
|
||||
// for (i = 0; i < deleteTestSize; i++) {
|
||||
// j = Math.floor(Math.random() * uniques)
|
||||
// temp = array[j]
|
||||
// if (newAVL.find(temp)) {
|
||||
// if (!newAVL.remove(temp)) {
|
||||
// throw new Error('delete not working properly')
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// })()
|
||||
|
||||
module.exports = AVLTree
|
||||
export { AVLTree }
|
||||
|
@ -170,8 +170,5 @@ function SHA1 (message) {
|
||||
return HH
|
||||
}
|
||||
|
||||
console.log(SHA1('A Test'))
|
||||
console.log(SHA1('A Test'))
|
||||
|
||||
// export SHA1 function
|
||||
module.exports = SHA1
|
||||
export { SHA1 }
|
||||
|
@ -185,4 +185,4 @@ function SHA256 (message) {
|
||||
}
|
||||
|
||||
// export SHA256 function
|
||||
module.exports = SHA256
|
||||
export { SHA256 }
|
||||
|
@ -41,4 +41,4 @@ const CheckKishnamurthyNumber = (number) => {
|
||||
return sumOfAllDigitFactorial === number
|
||||
}
|
||||
|
||||
module.exports = CheckKishnamurthyNumber
|
||||
export { CheckKishnamurthyNumber }
|
||||
|
@ -37,4 +37,4 @@ const CoPrimeCheck = (firstNumber, secondNumber) => {
|
||||
return GetEuclidGCD(firstNumber, secondNumber) === 1
|
||||
}
|
||||
|
||||
module.exports = CoPrimeCheck
|
||||
export { CoPrimeCheck }
|
||||
|
@ -29,4 +29,4 @@ const GetEuclidGCD = (arg1, arg2) => {
|
||||
return (less)
|
||||
}
|
||||
|
||||
module.exports = GetEuclidGCD
|
||||
export { GetEuclidGCD }
|
||||
|
@ -26,4 +26,4 @@ const ReverseNumber = (number) => {
|
||||
return reverseNumber
|
||||
}
|
||||
|
||||
module.exports = ReverseNumber
|
||||
export { ReverseNumber }
|
||||
|
@ -1,4 +1,4 @@
|
||||
const { binaryExponentiation } = require('../BinaryExponentiationRecursive')
|
||||
import { binaryExponentiation } from '../BinaryExponentiationRecursive'
|
||||
|
||||
describe('BinaryExponentiationRecursive', () => {
|
||||
it('should calculate 2 to the power of 10 correctly', () => {
|
||||
|
@ -4,8 +4,6 @@
|
||||
Find the sum of all the multiples of 3 or 5 below the provided parameter value number.
|
||||
*/
|
||||
|
||||
const readline = require('readline')
|
||||
|
||||
const multiplesThreeAndFive = (num) => {
|
||||
let total = 0
|
||||
// total for calculating the sum
|
||||
@ -17,11 +15,4 @@ const multiplesThreeAndFive = (num) => {
|
||||
return total
|
||||
}
|
||||
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
})
|
||||
rl.question('Enter a number: ', function (num) {
|
||||
console.log(multiplesThreeAndFive(num)) // multiples3_5 function to calculate the sum of multiples of 3 and 5 within num
|
||||
rl.close()
|
||||
})
|
||||
export { multiplesThreeAndFive }
|
@ -41,4 +41,4 @@ const AlternativeStringArrange = (str1, str2) => {
|
||||
return outStr
|
||||
}
|
||||
|
||||
module.exports = AlternativeStringArrange
|
||||
export { AlternativeStringArrange }
|
||||
|
@ -17,4 +17,4 @@ const CheckKebabCase = (varName) => {
|
||||
return pat.test(varName) && !varName.includes('_')
|
||||
}
|
||||
|
||||
module.exports = CheckKebabCase
|
||||
export { CheckKebabCase }
|
||||
|
@ -17,4 +17,4 @@ const CheckPascalCase = (VarName) => {
|
||||
return pat.test(VarName)
|
||||
}
|
||||
|
||||
module.exports = CheckPascalCase
|
||||
export { CheckPascalCase }
|
||||
|
Reference in New Issue
Block a user