mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-04 15:39:42 +08:00
Merge branch 'master' into master
This commit is contained in:
108
.github/workflows/UpdateDirectory.js
vendored
108
.github/workflows/UpdateDirectory.js
vendored
@ -1,108 +0,0 @@
|
||||
// requiring path and fs modules
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
let URL_BASE = "https://github.com/TheAlgorithms/Javascript/blob/master";
|
||||
let g_output = [];
|
||||
|
||||
let filepaths = [];
|
||||
function good_filepaths(top_dir = ".") {
|
||||
fs.readdir(top_dir, function(err, list) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
list.forEach(function(file) {
|
||||
let path = top_dir + "/" + file;
|
||||
if (!file.startsWith(".")) {
|
||||
fs.stat(path, function(err, stat) {
|
||||
if (stat && stat.isDirectory()) {
|
||||
good_filepaths(path);
|
||||
} else {
|
||||
if (file.toLowerCase().endsWith(".js")) {
|
||||
filepaths.push(path.slice(2));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
function md_prefix(i) {
|
||||
if (i) {
|
||||
let res = ' '.repeat(i);
|
||||
return res + "*";
|
||||
} else {
|
||||
return "\n##"
|
||||
}
|
||||
}
|
||||
|
||||
function print_path(old_path, new_path) {
|
||||
let old_parts = old_path.split(path.sep);
|
||||
let new_parts = new_path.split(path.sep);
|
||||
for (let i = 0; i < new_parts.length; ++i) {
|
||||
let new_part = new_parts[i];
|
||||
if (i + 1 > old_parts.len || old_parts[i] != new_part) {
|
||||
if (new_part) {
|
||||
g_output.push(`${md_prefix(i)} ${new_part.replace('_', ' ')}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new_path;
|
||||
}
|
||||
|
||||
function build_directory_md(top_dir = ".") {
|
||||
old_path = "";
|
||||
filepaths.sort(function(a, b) {
|
||||
if (a.toLowerCase() < b.toLowerCase()) return -1;
|
||||
if (a.toLowerCase() > b.toLowerCase()) return 1;
|
||||
return 0;
|
||||
});
|
||||
for (let filepath of filepaths) {
|
||||
file = filepath.split(path.sep);
|
||||
if (file.length == 1) {
|
||||
filepath = "";
|
||||
filename = file[0];
|
||||
} else {
|
||||
let total = file.length;
|
||||
filename = file[total - 1];
|
||||
filepath = file.splice(0, total - 1).join(path.sep);
|
||||
}
|
||||
if (filepath != old_path) {
|
||||
old_path = print_path(old_path, filepath);
|
||||
}
|
||||
let indent = 0;
|
||||
for (let i = 0; i < filepath.length; ++i) {
|
||||
if (filepath[i] == path.sep) {
|
||||
++indent;
|
||||
}
|
||||
}
|
||||
if (filepath) {
|
||||
++indent;
|
||||
}
|
||||
let urls = [URL_BASE, filepath, filename];
|
||||
let url = urls.join("/").replace(" ", "%20");
|
||||
// remove extension from filename
|
||||
filename = filename.split(".")[0];
|
||||
g_output.push(`${md_prefix(indent)} [${filename}](${url})`);
|
||||
}
|
||||
g_output = g_output.join('\n');
|
||||
return g_output;
|
||||
}
|
||||
|
||||
good_filepaths();
|
||||
setTimeout(() => {
|
||||
// once the filepaths have been computed
|
||||
build_directory_md();
|
||||
// console.log(filepaths);
|
||||
}, 1000);
|
||||
setTimeout(() => {
|
||||
// once the g_output has been constructed, write to the file
|
||||
fs.writeFile('DIRECTORY.md', g_output + '\n', (err) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
})
|
||||
// console.log(g_output);
|
||||
}, 1000);
|
83
.github/workflows/UpdateDirectory.mjs
vendored
Normal file
83
.github/workflows/UpdateDirectory.mjs
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
import { globby } from 'globby'
|
||||
|
||||
const URL_BASE = 'https://github.com/TheAlgorithms/Javascript/blob/master'
|
||||
|
||||
function pathPrefix (i) {
|
||||
if (i) {
|
||||
const res = ' '.repeat(i)
|
||||
return res + '*'
|
||||
} else {
|
||||
return '\n##'
|
||||
}
|
||||
}
|
||||
|
||||
function printPath (oldPath, newPath, output) {
|
||||
const oldParts = oldPath.split(path.sep)
|
||||
const newParts = newPath.split(path.sep)
|
||||
for (let i = 0; i < newParts.length; ++i) {
|
||||
const newPart = newParts[i]
|
||||
if (i + 1 > oldParts.length || oldParts[i] !== newPart) {
|
||||
if (newPart) {
|
||||
output.push(`${pathPrefix(i)} ${newPart.replace('_', ' ')}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
return newPath
|
||||
}
|
||||
|
||||
function pathsToMarkdown (filePaths) {
|
||||
const output = []
|
||||
|
||||
let oldPath = ''
|
||||
filePaths.sort(function (a, b) {
|
||||
if (a.toLowerCase() < b.toLowerCase()) return -1
|
||||
if (a.toLowerCase() > b.toLowerCase()) return 1
|
||||
return 0
|
||||
})
|
||||
for (let filepath of filePaths) {
|
||||
const file = filepath.split(path.sep)
|
||||
let filename = ''
|
||||
if (file.length === 1) {
|
||||
filepath = ''
|
||||
filename = file[0]
|
||||
} else {
|
||||
const total = file.length
|
||||
filename = file[total - 1]
|
||||
filepath = file.splice(0, total - 1).join(path.sep)
|
||||
}
|
||||
if (filepath !== oldPath) {
|
||||
oldPath = printPath(oldPath, filepath, output)
|
||||
}
|
||||
let indent = 0
|
||||
for (let i = 0; i < filepath.length; ++i) {
|
||||
if (filepath[i] === path.sep) {
|
||||
++indent
|
||||
}
|
||||
}
|
||||
if (filepath) {
|
||||
++indent
|
||||
}
|
||||
|
||||
// prepare the markdown-esque prefix to the file's line
|
||||
const prefix = pathPrefix(indent)
|
||||
|
||||
// remove extension from filename
|
||||
const name = filename.split('.')[0]
|
||||
|
||||
// create URL to the actual file on github
|
||||
const url = encodeURI([URL_BASE, filepath, filename].join('/'))
|
||||
|
||||
output.push(`${prefix} [${name}](${url})`)
|
||||
}
|
||||
|
||||
return output.join('\n')
|
||||
}
|
||||
|
||||
// get paths of all .js files - excluding node_modules, the .github folder, tests and config stuff
|
||||
globby(['**/*.js', '!(node_modules|.github)/**/*', '!**/*.test.js', '!babel.config.js'])
|
||||
// create markdown content
|
||||
.then(pathsToMarkdown)
|
||||
// write markdown to file
|
||||
.then(markdown => fs.writeFileSync('DIRECTORY.md', markdown + '\n', { encoding: 'utf8' }))
|
23
.github/workflows/ci.yml
vendored
Normal file
23
.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
name: Continuous Integration
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '14'
|
||||
|
||||
- name: 📦 Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: 🧪 Run tests
|
||||
run: |
|
||||
npm run doctest || true # TODO: Add all doctests
|
||||
npm test
|
||||
|
||||
- name: 💄 Code style
|
||||
run: npm run style
|
10
.github/workflows/commitAndPushDirectory.sh
vendored
Executable file
10
.github/workflows/commitAndPushDirectory.sh
vendored
Executable file
@ -0,0 +1,10 @@
|
||||
if ! git diff --quiet DIRECTORY.md; then
|
||||
echo Changes found, attempting to commit and push...
|
||||
git add DIRECTORY.md
|
||||
git commit -am "Auto-update DIRECTORY.md" || true
|
||||
git push --force origin HEAD:$GITHUB_REF || true
|
||||
echo ... done.
|
||||
else
|
||||
echo No changes found, exiting.
|
||||
fi
|
||||
|
24
.github/workflows/nodejs.yml
vendored
24
.github/workflows/nodejs.yml
vendored
@ -1,24 +0,0 @@
|
||||
name: Node CI
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [14.x]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: npm install, build, and test
|
||||
run: |
|
||||
npm install doctest standard --save-dev
|
||||
npx doctest **/*.js || true # TODO: Add all doctests
|
||||
npx standard
|
||||
npm ci
|
||||
npm run build --if-present
|
||||
npm test
|
||||
env:
|
||||
CI: true
|
28
.github/workflows/update_directory_md.yml
vendored
28
.github/workflows/update_directory_md.yml
vendored
@ -1,18 +1,26 @@
|
||||
# This GitHub Action updates the DIRECTORY.md file (if needed) when doing a git push
|
||||
name: update_directory_md
|
||||
name: Update Directory
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
update_directory_md:
|
||||
updateDirectory:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: actions/setup-node@v1
|
||||
- run: |
|
||||
node .github/workflows/UpdateDirectory.js
|
||||
cat DIRECTORY.md
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '14'
|
||||
|
||||
- name: 📦 Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: 🗄️ Create Directory from JS files
|
||||
run: node .github/workflows/UpdateDirectory.mjs
|
||||
|
||||
- name: 🤓 Commit & push new Directory (if needed)
|
||||
run: |
|
||||
git config --global user.name github-actions
|
||||
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
|
||||
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
|
||||
git add DIRECTORY.md
|
||||
git commit -am "updating DIRECTORY.md" || true
|
||||
git push --force origin HEAD:$GITHUB_REF || true
|
||||
.github/workflows/commitAndPushDirectory.sh
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* Given an ordered set W of non-negative integers and a value K,
|
||||
* determine all possible subsets from the given set W whose sum
|
||||
* of its elemets equals to the given value K.
|
||||
* of its elements equals to the given value K.
|
||||
*
|
||||
* More info: https://www.geeksforgeeks.org/subset-sum-backtracking-4/
|
||||
*/
|
||||
@ -53,7 +53,7 @@ const sumOfSubset = (set, subset, setindex, sum, targetSum) => {
|
||||
targetSum
|
||||
)
|
||||
|
||||
// Concat the recursive result with current result arary
|
||||
// Concat the recursive result with current result array
|
||||
results = [...results, ...subsetResult]
|
||||
})
|
||||
|
||||
|
@ -3,13 +3,13 @@
|
||||
license: GPL-3.0 or later
|
||||
|
||||
This script will find number of 1's
|
||||
in binary representain of given number
|
||||
in binary representation of given number
|
||||
|
||||
*/
|
||||
|
||||
function BinaryCountSetBits (a) {
|
||||
'use strict'
|
||||
// convert number into binary representation and return number of set bits in binary representaion
|
||||
// convert number into binary representation and return number of set bits in binary representation
|
||||
return a.toString(2).split('1').length - 1
|
||||
}
|
||||
|
||||
|
42
Cache/Memoize.js
Normal file
42
Cache/Memoize.js
Normal file
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Memoize
|
||||
*
|
||||
* From [Wikipedia](https://en.wikipedia.org/wiki/Memoization),
|
||||
* memoization is an optimization technique
|
||||
* used primarily to speed up computer programs,
|
||||
* by storing the results of expensive function calls
|
||||
* and returning the cached result when the same inputs occur again
|
||||
*
|
||||
* This function is a first class objects,
|
||||
* which lets us use it as [Higher-Order Function](https://eloquentjavascript.net/05_higher_order.html)
|
||||
* and return another function
|
||||
*
|
||||
* @param {Function} func Original function
|
||||
* @returns {Function} Memoized function
|
||||
*/
|
||||
export const memoize = (func) => {
|
||||
// Initialization of a slot to store the function result
|
||||
const cache = {}
|
||||
|
||||
return (...args) => {
|
||||
// Retrieving the first argument of the function
|
||||
const [arg] = args
|
||||
|
||||
/**
|
||||
* Checks if the argument is already present in the cache,
|
||||
* then return the associated value / result
|
||||
*/
|
||||
if (arg in cache) {
|
||||
return cache[arg]
|
||||
}
|
||||
|
||||
/**
|
||||
* If the argument is not yet present in the cache,
|
||||
* execute original function and save its value / result in cache,
|
||||
* finally return it
|
||||
*/
|
||||
const result = func(arg)
|
||||
cache[arg] = result
|
||||
return result
|
||||
}
|
||||
}
|
37
Cache/test/Memoize.test.js
Normal file
37
Cache/test/Memoize.test.js
Normal file
@ -0,0 +1,37 @@
|
||||
import { memoize } from '../Memoize'
|
||||
|
||||
const fibonacci = (n) => {
|
||||
if (n < 2) {
|
||||
return n
|
||||
}
|
||||
|
||||
return fibonacci(n - 2) + fibonacci(n - 1)
|
||||
}
|
||||
|
||||
const factorial = (n) => {
|
||||
if (n === 0) {
|
||||
return 1
|
||||
}
|
||||
|
||||
return n * factorial(n - 1)
|
||||
}
|
||||
|
||||
describe('Memoize', () => {
|
||||
it('expects the fibonacci function to use the cache on the second call', () => {
|
||||
const memoFibonacci = memoize(fibonacci)
|
||||
|
||||
expect(memoFibonacci(5)).toEqual(fibonacci(5))
|
||||
expect(memoFibonacci(5)).toEqual(5)
|
||||
expect(memoFibonacci(10)).toEqual(fibonacci(10))
|
||||
expect(memoFibonacci(10)).toEqual(55)
|
||||
})
|
||||
|
||||
it('expects the factorial function to use the cache on the second call', () => {
|
||||
const memoFactorial = memoize(factorial)
|
||||
|
||||
expect(memoFactorial(5)).toEqual(factorial(5))
|
||||
expect(memoFactorial(5)).toEqual(120)
|
||||
expect(memoFactorial(10)).toEqual(factorial(10))
|
||||
expect(memoFactorial(10)).toEqual(3628800)
|
||||
})
|
||||
})
|
@ -48,7 +48,7 @@ function keyFinder (str) { // str is used to get the input of encrypted string
|
||||
// console.log( k + outStrElement + wordBank[i] );//debug
|
||||
|
||||
// this part need to be optimize with the calculation of the number of occurrence of word's probabilities
|
||||
// linked list will be used in the next stage of development to calculate the number of occurace of the key
|
||||
// linked list will be used in the next stage of development to calculate the number of occurrence of the key
|
||||
if (wordBank[i] === outStrElement) {
|
||||
return k // return the key number if founded
|
||||
}
|
||||
|
@ -22,9 +22,9 @@ const DateDayDifference = (date1, date2) => {
|
||||
if (typeof date1 !== 'string' && typeof date2 !== 'string') {
|
||||
return new TypeError('Argument is not a string.')
|
||||
}
|
||||
// extarct the first date
|
||||
// extract the first date
|
||||
const [firstDateDay, firstDateMonth, firstDateYear] = date1.split('/').map((ele) => Number(ele))
|
||||
// extarct the second date
|
||||
// extract the second date
|
||||
const [secondDateDay, secondDateMonth, secondDateYear] = date2.split('/').map((ele) => Number(ele))
|
||||
// check the both data are valid or not.
|
||||
if (firstDateDay < 0 || firstDateDay > 31 ||
|
||||
|
@ -44,7 +44,7 @@ const DateToDay = (date) => {
|
||||
if (typeof date !== 'string') {
|
||||
return new TypeError('Argument is not a string.')
|
||||
}
|
||||
// extarct the date
|
||||
// extract the date
|
||||
const [day, month, year] = date.split('/').map((x) => Number(x))
|
||||
// check the data are valid or not.
|
||||
if (day < 0 || day > 31 || month > 12 || month < 0) {
|
||||
|
@ -5,7 +5,7 @@
|
||||
want some changes in hour value.
|
||||
|
||||
Input Formate -> 07:05:45PM
|
||||
Output Fromate -> 19:05:45
|
||||
Output Formate -> 19:05:45
|
||||
|
||||
Problem & Explanation Source : https://www.mathsisfun.com/time.html
|
||||
*/
|
||||
|
@ -1,19 +1,23 @@
|
||||
/*
|
||||
Problem statement and Explanation : https://www.codeproject.com/Tips/162540/Letter-Case-Conversion-Algorithms-Title-Case-Toggl
|
||||
Problem statement and Explanation : https://www.codeproject.com/Tips/162540/Letter-Case-Conversion-Algorithms-Title-Case-Toggl.
|
||||
[Title case](https://en.wikipedia.org/wiki/Title_case) is a style where all words are capitalized. Officially, title case
|
||||
does not capitalize some words, such as very short words like "a" or "is", but for the purposes of this function, a general approach
|
||||
is taken where all words are capitalized regardless of length.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The TitleCaseConversion converts a string into a title case string.
|
||||
* @param {String} inputString input string
|
||||
* @returns {String}
|
||||
* The titleCaseConversion function converts a string into a title case string.
|
||||
* @param {string} inputString The input string which can have any types of letter casing.
|
||||
* @returns {string} A string that is in title case.
|
||||
*/
|
||||
const TitleCaseConversion = (inputString) => {
|
||||
// Extact all space seprated string.
|
||||
const titleCaseConversion = (inputString) => {
|
||||
if (inputString === '') return ''
|
||||
// Extract all space separated string.
|
||||
const stringCollections = inputString.split(' ').map(word => {
|
||||
let firstChar = ''
|
||||
// Get a character code by the use charCodeAt method.
|
||||
// Get the [ASCII](https://en.wikipedia.org/wiki/ASCII) character code by the use charCodeAt method.
|
||||
const firstCharCode = word[0].charCodeAt()
|
||||
// If the character code lies between 97 to 122 it means they are in the lower case so convert it.
|
||||
// If the ASCII character code lies between 97 to 122 it means they are in the lowercase so convert it.
|
||||
if (firstCharCode >= 97 && firstCharCode <= 122) {
|
||||
// Convert the case by use of the above explanation.
|
||||
firstChar += String.fromCharCode(firstCharCode - 32)
|
||||
@ -22,9 +26,9 @@ const TitleCaseConversion = (inputString) => {
|
||||
firstChar += word[0]
|
||||
}
|
||||
const newWordChar = word.slice(1).split('').map(char => {
|
||||
// Get a character code by the use charCodeAt method.
|
||||
// Get the ASCII character code by the use charCodeAt method.
|
||||
const presentCharCode = char.charCodeAt()
|
||||
// If the character code lies between 65 to 90 it means they are in the upper case so convert it.
|
||||
// If the ASCII character code lies between 65 to 90, it means they are in the uppercase so convert it.
|
||||
if (presentCharCode >= 65 && presentCharCode <= 90) {
|
||||
// Convert the case by use of the above explanation.
|
||||
return String.fromCharCode(presentCharCode + 32)
|
||||
@ -32,11 +36,11 @@ const TitleCaseConversion = (inputString) => {
|
||||
// Else return the characters without any modification.
|
||||
return char
|
||||
})
|
||||
// return the first converted character and remaining character string.
|
||||
// Return the first converted character and remaining character string.
|
||||
return firstChar + newWordChar.join('')
|
||||
})
|
||||
// convert all words in a string and return it.
|
||||
// Convert all words in a string and return it.
|
||||
return stringCollections.join(' ')
|
||||
}
|
||||
|
||||
module.exports = TitleCaseConversion
|
||||
export { titleCaseConversion }
|
||||
|
@ -1,26 +1,26 @@
|
||||
/*
|
||||
Explanation :- a user gives a String (it can be incomplete lower or
|
||||
partial lower) and then the program would convert it into a
|
||||
complete(all characters in upper case) upper case string. The
|
||||
logic we have used in the following program is: All the lower case
|
||||
characters (a-z) has ASCII value ranging from 97 to 122 and their
|
||||
corresponding upper case characters (A-Z) have ASCII values 32
|
||||
Explanation :- A user gives a string (it can be incomplete lowercase or
|
||||
partially in lowercase) and then the program converts it into a
|
||||
completely (all characters in uppercase) uppercase string. The
|
||||
logic we have used in the following program is: All the lowercase
|
||||
characters (a-z) has [ASCII](https://en.wikipedia.org/wiki/ASCII) value ranging from 97 to 122 and their
|
||||
corresponding uppercase characters (A-Z) have ASCII values 32
|
||||
lesser than them. For example ‘a‘ has an ASCII value of 97
|
||||
and ‘A‘ has an ASCII value of 65 (97 - 32). The same applies to other
|
||||
characters.
|
||||
*/
|
||||
|
||||
/**
|
||||
* UpperCaseConversion takes any case-style string and converts it to the upper case-style string.
|
||||
* @param {String} inputString any case style string
|
||||
* @returns {String} upper case string
|
||||
* upperCaseConversion takes any case-style string and converts it to the uppercase-style string.
|
||||
* @param {string} inputString Any case style string
|
||||
* @returns {string} Uppercase string
|
||||
*/
|
||||
const UpperCaseConversion = (inputString) => {
|
||||
const upperCaseConversion = (inputString) => {
|
||||
// Take a string and split it into characters.
|
||||
const newString = inputString.split('').map(char => {
|
||||
// Get a character code by the use charCodeAt method.
|
||||
const presentCharCode = char.charCodeAt()
|
||||
// If the character code lies between 97 to 122 it means they are in the lower case so convert it.
|
||||
// If the character code lies between 97 to 122, it means they are in the lowercase so convert it.
|
||||
if (presentCharCode >= 97 && presentCharCode <= 122) {
|
||||
// Convert the case by use of the above explanation.
|
||||
return String.fromCharCode(presentCharCode - 32)
|
||||
@ -32,4 +32,4 @@ const UpperCaseConversion = (inputString) => {
|
||||
return newString.join('')
|
||||
}
|
||||
|
||||
module.exports = UpperCaseConversion
|
||||
export { upperCaseConversion }
|
||||
|
51
Conversions/test/TitleCaseConversion.test.js
Normal file
51
Conversions/test/TitleCaseConversion.test.js
Normal file
@ -0,0 +1,51 @@
|
||||
import { titleCaseConversion } from '../TitleCaseConversion'
|
||||
|
||||
describe(('Tests for the titleCaseConversion function'), () => {
|
||||
it('should return an empty string when the input is an empty string', () => {
|
||||
expect(titleCaseConversion('')).toEqual('')
|
||||
})
|
||||
|
||||
it('should return the input string when the input string is a title case string', () => {
|
||||
expect(titleCaseConversion('A Proper Title Case String')).toEqual('A Proper Title Case String')
|
||||
})
|
||||
|
||||
it('should return a title case string when input is an all-uppercase string', () => {
|
||||
expect(titleCaseConversion('ALL UPPER CASE')).toEqual('All Upper Case')
|
||||
})
|
||||
|
||||
it('should return a title case string when input is a title case string of with spaces', () => {
|
||||
expect(titleCaseConversion('ALL UPPERCASE')).toEqual('All Uppercase')
|
||||
})
|
||||
|
||||
it('should return a title case string when input is a title case string of with no spaces', () => {
|
||||
expect(titleCaseConversion('ALLUPPERCASE')).toEqual('Alluppercase')
|
||||
})
|
||||
|
||||
it('should return a title case string when input is a title case string with punctuation', () => {
|
||||
expect(titleCaseConversion('All Title Case!')).toEqual('All Title Case!')
|
||||
})
|
||||
|
||||
it('should return a title case string when input is an all-lowercase string with no spaces', () => {
|
||||
expect(titleCaseConversion('lowercaseinput')).toEqual('Lowercaseinput')
|
||||
})
|
||||
|
||||
it('should return a title case string when input is an all-lowercase string with spaces', () => {
|
||||
expect(titleCaseConversion('lowercase input')).toEqual('Lowercase Input')
|
||||
})
|
||||
|
||||
it('should return a title case string when input is an all-lowercase string with punctuation', () => {
|
||||
expect(titleCaseConversion('lower, case, input.')).toEqual('Lower, Case, Input.')
|
||||
})
|
||||
|
||||
it('should return a title case string when input is an mixed-case string', () => {
|
||||
expect(titleCaseConversion('mixeD CaSe INPuT')).toEqual('Mixed Case Input')
|
||||
})
|
||||
|
||||
it('should return a title case string when input is an mixed-case string with no spaces', () => {
|
||||
expect(titleCaseConversion('mixeDCaSeINPuT')).toEqual('Mixedcaseinput')
|
||||
})
|
||||
|
||||
it('should return a title case string when input is an mixed-case string with punctuation', () => {
|
||||
expect(titleCaseConversion('mixeD, CaSe, INPuT!')).toEqual('Mixed, Case, Input!')
|
||||
})
|
||||
})
|
43
Conversions/test/UpperCaseConverstion.test.js
Normal file
43
Conversions/test/UpperCaseConverstion.test.js
Normal file
@ -0,0 +1,43 @@
|
||||
import { upperCaseConversion } from '../UpperCaseConversion'
|
||||
|
||||
describe(('Test the upperCaseConversion function'), () => {
|
||||
it('should return an empty string when the input is an empty string', () => {
|
||||
expect(upperCaseConversion('')).toEqual('')
|
||||
})
|
||||
|
||||
it('should return an all-uppercase string when input is an all-uppercase string', () => {
|
||||
expect(upperCaseConversion('ALLUPPERCASE')).toEqual('ALLUPPERCASE')
|
||||
})
|
||||
|
||||
it('should return an all-uppercase string when input is an all-uppercase string with spaces', () => {
|
||||
expect(upperCaseConversion('ALL UPPERCASE')).toEqual('ALL UPPERCASE')
|
||||
})
|
||||
|
||||
it('should return an all-uppercase string when input is an all-uppercase string with punctuation', () => {
|
||||
expect(upperCaseConversion('ALL UPPER-CASE!')).toEqual('ALL UPPER-CASE!')
|
||||
})
|
||||
|
||||
it('should return an all-uppercase string when input is an all-lowercase string', () => {
|
||||
expect(upperCaseConversion('lowercaseinput')).toEqual('LOWERCASEINPUT')
|
||||
})
|
||||
|
||||
it('should return an all-uppercase string when input is an all-lowercase string with spaces', () => {
|
||||
expect(upperCaseConversion('lowercase input')).toEqual('LOWERCASE INPUT')
|
||||
})
|
||||
|
||||
it('should return an all-uppercase string when input is an all-lowercase string with punctuation', () => {
|
||||
expect(upperCaseConversion('lower-case, input.')).toEqual('LOWER-CASE, INPUT.')
|
||||
})
|
||||
|
||||
it('should return an all-uppercase string when input is an mixed-case string', () => {
|
||||
expect(upperCaseConversion('mixeDCaSeINPuT')).toEqual('MIXEDCASEINPUT')
|
||||
})
|
||||
|
||||
it('should return an all-uppercase string when input is an mixed-case string with spaces', () => {
|
||||
expect(upperCaseConversion('mixeD CaSe INPuT')).toEqual('MIXED CASE INPUT')
|
||||
})
|
||||
|
||||
it('should return an all-uppercase string when input is an mixed-case string with punctuation', () => {
|
||||
expect(upperCaseConversion('mixeD-CaSe INPuT!')).toEqual('MIXED-CASE INPUT!')
|
||||
})
|
||||
})
|
97
DIRECTORY.md
97
DIRECTORY.md
@ -1,6 +1,4 @@
|
||||
|
||||
## [babel](https://github.com/TheAlgorithms/Javascript/blob/master//babel.config.js)
|
||||
|
||||
## Backtracking
|
||||
* [GeneratePermutations](https://github.com/TheAlgorithms/Javascript/blob/master/Backtracking/GeneratePermutations.js)
|
||||
* [KnightTour](https://github.com/TheAlgorithms/Javascript/blob/master/Backtracking/KnightTour.js)
|
||||
@ -8,21 +6,15 @@
|
||||
* [RatInAMaze](https://github.com/TheAlgorithms/Javascript/blob/master/Backtracking/RatInAMaze.js)
|
||||
* [Sudoku](https://github.com/TheAlgorithms/Javascript/blob/master/Backtracking/Sudoku.js)
|
||||
* [SumOfSubset](https://github.com/TheAlgorithms/Javascript/blob/master/Backtracking/SumOfSubset.js)
|
||||
* tests
|
||||
* [NQueen](https://github.com/TheAlgorithms/Javascript/blob/master/Backtracking/tests/NQueen.test.js)
|
||||
* [RatInAMaze](https://github.com/TheAlgorithms/Javascript/blob/master/Backtracking/tests/RatInAMaze.test.js)
|
||||
* [Sudoku](https://github.com/TheAlgorithms/Javascript/blob/master/Backtracking/tests/Sudoku.test.js)
|
||||
* [SumOfSubset](https://github.com/TheAlgorithms/Javascript/blob/master/Backtracking/tests/SumOfSubset.test.js)
|
||||
|
||||
## Bit-Manipulation
|
||||
* [BinaryCountSetBits](https://github.com/TheAlgorithms/Javascript/blob/master/Bit-Manipulation/BinaryCountSetBits.js)
|
||||
* [SetBit](https://github.com/TheAlgorithms/Javascript/blob/master/Bit-Manipulation/SetBit.js)
|
||||
* test
|
||||
* [SetBit](https://github.com/TheAlgorithms/Javascript/blob/master/Bit-Manipulation/test/SetBit.test.js)
|
||||
|
||||
## Cache
|
||||
* [LFUCache](https://github.com/TheAlgorithms/Javascript/blob/master/Cache/LFUCache.js)
|
||||
* [LRUCache](https://github.com/TheAlgorithms/Javascript/blob/master/Cache/LRUCache.js)
|
||||
* [Memoize](https://github.com/TheAlgorithms/Javascript/blob/master/Cache/Memoize.js)
|
||||
|
||||
## Cellular-Automata
|
||||
* [ConwaysGameOfLife](https://github.com/TheAlgorithms/Javascript/blob/master/Cellular-Automata/ConwaysGameOfLife.js)
|
||||
@ -53,16 +45,12 @@
|
||||
* [RgbHsvConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/RgbHsvConversion.js)
|
||||
* [RGBToHex](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/RGBToHex.js)
|
||||
* [RomanToDecimal](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/RomanToDecimal.js)
|
||||
* test
|
||||
* [DecimalToHex](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/test/DecimalToHex.test.js)
|
||||
* [DecimalToRoman](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/test/DecimalToRoman.test.js)
|
||||
* [TitleCaseConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/TitleCaseConversion.js)
|
||||
* [UpperCaseConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/UpperCaseConversion.js)
|
||||
|
||||
## Data-Structures
|
||||
* Array
|
||||
* [QuickSelect](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Array/QuickSelect.js)
|
||||
* [QuickSelect](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Array/QuickSelect.test.js)
|
||||
* Graph
|
||||
* [Graph](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Graph/Graph.js)
|
||||
* [Graph2](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Graph/Graph2.js)
|
||||
@ -107,11 +95,6 @@
|
||||
* [Shuf](https://github.com/TheAlgorithms/Javascript/blob/master/Dynamic-Programming/Shuf.js)
|
||||
* [SieveOfEratosthenes](https://github.com/TheAlgorithms/Javascript/blob/master/Dynamic-Programming/SieveOfEratosthenes.js)
|
||||
* [SudokuSolver](https://github.com/TheAlgorithms/Javascript/blob/master/Dynamic-Programming/SudokuSolver.js)
|
||||
* tests
|
||||
* [CoinChange](https://github.com/TheAlgorithms/Javascript/blob/master/Dynamic-Programming/tests/CoinChange.test.js)
|
||||
* [LongestPalindromicSubsequence](https://github.com/TheAlgorithms/Javascript/blob/master/Dynamic-Programming/tests/LongestPalindromicSubsequence.test.js)
|
||||
* [LongestValidParentheses](https://github.com/TheAlgorithms/Javascript/blob/master/Dynamic-Programming/tests/LongestValidParentheses.test.js)
|
||||
* [TrappingRainWater](https://github.com/TheAlgorithms/Javascript/blob/master/Dynamic-Programming/tests/TrappingRainWater.test.js)
|
||||
* [TrappingRainWater](https://github.com/TheAlgorithms/Javascript/blob/master/Dynamic-Programming/TrappingRainWater.js)
|
||||
* [ZeroOneKnapsack](https://github.com/TheAlgorithms/Javascript/blob/master/Dynamic-Programming/ZeroOneKnapsack.js)
|
||||
|
||||
@ -133,8 +116,6 @@
|
||||
* [NodeNeighbors](https://github.com/TheAlgorithms/Javascript/blob/master/Graphs/NodeNeighbors.js)
|
||||
* [NumberOfIslands](https://github.com/TheAlgorithms/Javascript/blob/master/Graphs/NumberOfIslands.js)
|
||||
* [PrimMST](https://github.com/TheAlgorithms/Javascript/blob/master/Graphs/PrimMST.js)
|
||||
* test
|
||||
* [BellmanFord](https://github.com/TheAlgorithms/Javascript/blob/master/Graphs/test/BellmanFord.test.js)
|
||||
|
||||
## Hashes
|
||||
* [SHA1](https://github.com/TheAlgorithms/Javascript/blob/master/Hashes/SHA1.js)
|
||||
@ -199,52 +180,11 @@
|
||||
* [Softmax](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/Softmax.js)
|
||||
* [SquareRoot](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/SquareRoot.js)
|
||||
* [SumOfDigits](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/SumOfDigits.js)
|
||||
* test
|
||||
* [Abs](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Abs.test.js)
|
||||
* [Area](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Area.test.js)
|
||||
* [ArmstrongNumber](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/ArmstrongNumber.test.js)
|
||||
* [AverageMean](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/AverageMean.test.js)
|
||||
* [AverageMedian](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/AverageMedian.test.js)
|
||||
* [BInaryConvert](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/BInaryConvert.test.js)
|
||||
* [BinaryExponentiationIterative](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/BinaryExponentiationIterative.test.js)
|
||||
* [Coordinate](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Coordinate.test.js)
|
||||
* [DegreeToRadian](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/DegreeToRadian.test.js)
|
||||
* [DigitSum](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/DigitSum.test.js)
|
||||
* [EulersTotientFunction](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/EulersTotientFunction.test.js)
|
||||
* [Factorial](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Factorial.test.js)
|
||||
* [Factors](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Factors.test.js)
|
||||
* [FareyApproximation](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/FareyApproximation.test.js)
|
||||
* [Fibonacci](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Fibonacci.test.js)
|
||||
* [FindHcf](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/FindHcf.test.js)
|
||||
* [FindLcm](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/FindLcm.test.js)
|
||||
* [GridGet](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/GridGet.test.js)
|
||||
* [IsDivisible](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/IsDivisible.test.js)
|
||||
* [IsEven](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/IsEven.test.js)
|
||||
* [MeanSquareError](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/MeanSquareError.test.js)
|
||||
* [ModularBinaryExponentiationRecursive](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/ModularBinaryExponentiationRecursive.test.js)
|
||||
* [NumberOfDigits](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/NumberOfDigits.test.js)
|
||||
* [Palindrome](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Palindrome.test.js)
|
||||
* [PascalTriangle](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/PascalTriangle.test.js)
|
||||
* [PerfectCube](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/PerfectCube.test.js)
|
||||
* [PerfectNumber](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/PerfectNumber.test.js)
|
||||
* [PerfectSquare](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/PerfectSquare.test.js)
|
||||
* [PiApproximationMonteCarlo](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/PiApproximationMonteCarlo.test.js)
|
||||
* [Polynomial](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Polynomial.test.js)
|
||||
* [Pow](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Pow.test.js)
|
||||
* [PrimeCheck](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/PrimeCheck.test.js)
|
||||
* [RadianToDegree](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/RadianToDegree.test.js)
|
||||
* [ReversePolishNotation](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/ReversePolishNotation.test.js)
|
||||
* [SieveOfEratosthenes](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/SieveOfEratosthenes.test.js)
|
||||
* [Softmax](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Softmax.test.js)
|
||||
* [SumOfDigits](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/SumOfDigits.test.js)
|
||||
* [Volume](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Volume.test.js)
|
||||
* [Volume](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/Volume.js)
|
||||
* [WhileLoopFactorial](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/WhileLoopFactorial.js)
|
||||
|
||||
## Navigation
|
||||
* [Haversine](https://github.com/TheAlgorithms/Javascript/blob/master/Navigation/Haversine.js)
|
||||
* test
|
||||
* [Haversine](https://github.com/TheAlgorithms/Javascript/blob/master/Navigation/test/Haversine.test.js)
|
||||
|
||||
## Project-Euler
|
||||
* [Problem013](https://github.com/TheAlgorithms/Javascript/blob/master/Project-Euler/Problem013.js)
|
||||
@ -261,9 +201,6 @@
|
||||
* [Problem7](https://github.com/TheAlgorithms/Javascript/blob/master/Project-Euler/Problem7.js)
|
||||
* [Problem8](https://github.com/TheAlgorithms/Javascript/blob/master/Project-Euler/Problem8.js)
|
||||
* [Problem9](https://github.com/TheAlgorithms/Javascript/blob/master/Project-Euler/Problem9.js)
|
||||
* test
|
||||
* [Problem10](https://github.com/TheAlgorithms/Javascript/blob/master/Project-Euler/test/Problem10.test.js)
|
||||
* [Problem8](https://github.com/TheAlgorithms/Javascript/blob/master/Project-Euler/test/Problem8.test.js)
|
||||
|
||||
## Recursive
|
||||
* [BinaryEquivalent](https://github.com/TheAlgorithms/Javascript/blob/master/Recursive/BinaryEquivalent.js)
|
||||
@ -288,9 +225,6 @@
|
||||
* [SlidingWindow](https://github.com/TheAlgorithms/Javascript/blob/master/Search/SlidingWindow.js)
|
||||
* [StringSearch](https://github.com/TheAlgorithms/Javascript/blob/master/Search/StringSearch.js)
|
||||
* [TernarySearch](https://github.com/TheAlgorithms/Javascript/blob/master/Search/TernarySearch.js)
|
||||
* test
|
||||
* [SlidingWindow](https://github.com/TheAlgorithms/Javascript/blob/master/Search/test/SlidingWindow.test.js)
|
||||
* [TernarySearch](https://github.com/TheAlgorithms/Javascript/blob/master/Search/test/TernarySearch.test.js)
|
||||
|
||||
## Sorts
|
||||
* [BeadSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/BeadSort.js)
|
||||
@ -317,10 +251,6 @@
|
||||
* [RadixSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/RadixSort.js)
|
||||
* [SelectionSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/SelectionSort.js)
|
||||
* [ShellSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/ShellSort.js)
|
||||
* test
|
||||
* [FisherYatesShuffle](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/test/FisherYatesShuffle.test.js)
|
||||
* [QuickSortRecursive](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/test/QuickSortRecursive.test.js)
|
||||
* [SelectionSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/test/SelectionSort.test.js)
|
||||
* [TimSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/TimSort.js)
|
||||
* [TopologicalSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/TopologicalSort.js)
|
||||
* [WiggleSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/WiggleSort.js)
|
||||
@ -352,36 +282,11 @@
|
||||
* [ReverseString](https://github.com/TheAlgorithms/Javascript/blob/master/String/ReverseString.js)
|
||||
* [ReverseWords](https://github.com/TheAlgorithms/Javascript/blob/master/String/ReverseWords.js)
|
||||
* [ScrambleStrings](https://github.com/TheAlgorithms/Javascript/blob/master/String/ScrambleStrings.js)
|
||||
* test
|
||||
* [CheckAnagram](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/CheckAnagram.test.js)
|
||||
* [CheckCamelCase](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/CheckCamelCase.test.js)
|
||||
* [CheckFlatCase](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/CheckFlatCase.test.js)
|
||||
* [CheckPalindrome](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/CheckPalindrome.test.js)
|
||||
* [CheckPangram](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/CheckPangram.test.js)
|
||||
* [CheckSnakeCase](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/CheckSnakeCase.test.js)
|
||||
* [CheckVowels](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/CheckVowels.test.js)
|
||||
* [CheckWordOcurrence](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/CheckWordOcurrence.test.js)
|
||||
* [CreatePermutations](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/CreatePermutations.test.js)
|
||||
* [DiceCoefficient](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/DiceCoefficient.test.js)
|
||||
* [FormatPhoneNumber](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/FormatPhoneNumber.test.js)
|
||||
* [HammingDistance](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/HammingDistance.test.js)
|
||||
* [KMPPatternSearching](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/KMPPatternSearching.test.js)
|
||||
* [LevenshteinDistance](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/LevenshteinDistance.test.js)
|
||||
* [MaxCharacter](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/MaxCharacter.test.js)
|
||||
* [MaxWord](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/MaxWord.test.js)
|
||||
* [PatternMatching](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/PatternMatching.test.js)
|
||||
* [PermutateString](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/PermutateString.test.js)
|
||||
* [ReverseString](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/ReverseString.test.js)
|
||||
* [ReverseWords](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/ReverseWords.test.js)
|
||||
* [ScrambleStrings](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/ScrambleStrings.test.js)
|
||||
* [ValidateEmail](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/ValidateEmail.test.js)
|
||||
* [ValidateEmail](https://github.com/TheAlgorithms/Javascript/blob/master/String/ValidateEmail.js)
|
||||
|
||||
## Timing-Functions
|
||||
* [GetMonthDays](https://github.com/TheAlgorithms/Javascript/blob/master/Timing-Functions/GetMonthDays.js)
|
||||
* [IntervalTimer](https://github.com/TheAlgorithms/Javascript/blob/master/Timing-Functions/IntervalTimer.js)
|
||||
* test
|
||||
* [GetMonthDays](https://github.com/TheAlgorithms/Javascript/blob/master/Timing-Functions/test/GetMonthDays.test.js)
|
||||
|
||||
## Trees
|
||||
* [BreadthFirstTreeTraversal](https://github.com/TheAlgorithms/Javascript/blob/master/Trees/BreadthFirstTreeTraversal.js)
|
||||
|
@ -11,7 +11,7 @@ function main () {
|
||||
Note:
|
||||
* While Solving the problem in given link below, don't use main() function.
|
||||
* Just use only the code inside main() function.
|
||||
* The purpose of using main() function here is to aviod global variables.
|
||||
* The purpose of using main() function here is to avoid global variables.
|
||||
|
||||
Link for the Problem: https://leetcode.com/problems/linked-list-cycle/
|
||||
*/
|
||||
|
@ -10,7 +10,7 @@ function main () {
|
||||
Note:
|
||||
* While Solving the problem in given link below, don't use main() function.
|
||||
* Just use only the code inside main() function.
|
||||
* The purpose of using main() function here is to aviod global variables.
|
||||
* The purpose of using main() function here is to avoid global variables.
|
||||
|
||||
Link for the Problem: https://leetcode.com/problems/rotate-list/
|
||||
*/
|
||||
|
@ -37,7 +37,7 @@ let utils;
|
||||
*/
|
||||
const AVLTree = (function () {
|
||||
function _avl (comp) {
|
||||
/** @public compartor function */
|
||||
/** @public comparator function */
|
||||
this._comp = undefined
|
||||
if (comp !== undefined) {
|
||||
this._comp = comp
|
||||
@ -119,7 +119,7 @@ const AVLTree = (function () {
|
||||
node._right = rightRotate(node._right)
|
||||
return leftRotate(node) // Right Left
|
||||
}
|
||||
return leftRotate(node) // Rigth Right
|
||||
return leftRotate(node) // Right Right
|
||||
}
|
||||
// implement avl tree insertion
|
||||
const insert = function (root, val, tree) {
|
||||
@ -202,7 +202,7 @@ const AVLTree = (function () {
|
||||
return true
|
||||
}
|
||||
/**
|
||||
* TO check is a particluar element exists or not
|
||||
* TO check is a particular element exists or not
|
||||
* @param {any} _val
|
||||
* @returns {Boolean} exists or not
|
||||
*/
|
||||
|
@ -14,7 +14,7 @@ function Trie () {
|
||||
this.root = new TrieNode(null, null)
|
||||
}
|
||||
|
||||
// Recursively finds the occurence of all words in a given node
|
||||
// Recursively finds the occurrence of all words in a given node
|
||||
Trie.findAllWords = function (root, word, output) {
|
||||
if (root === null) return
|
||||
if (root.count > 0) {
|
||||
@ -79,15 +79,15 @@ Trie.prototype.remove = function (word, count) {
|
||||
child = child.children[key]
|
||||
}
|
||||
|
||||
// Delete no of occurences specified
|
||||
// Delete no of occurrences specified
|
||||
if (child.count >= count) child.count -= count
|
||||
else child.count = 0
|
||||
|
||||
// If some occurences are left we dont delete it or else
|
||||
// If some occurrences are left we dont delete it or else
|
||||
// if the object forms some other objects prefix we dont delete it
|
||||
// For checking an empty object
|
||||
// https://stackoverflow.com/questions/679915/how-do-i-test-for-an-empty-javascript-object
|
||||
if (child.count <= 0 && (Object.keys(child.children).length && child.childre.constructor === Object)) {
|
||||
if (child.count <= 0 && (Object.keys(child.children).length && child.children.constructor === Object)) {
|
||||
child.parent.children[child.key] = undefined
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ function KadaneAlgo (array) {
|
||||
}
|
||||
}
|
||||
return maxSum
|
||||
// This function returns largest sum contigous sum in a array
|
||||
// This function returns largest sum contiguous sum in a array
|
||||
}
|
||||
function main () {
|
||||
const myArray = [1, 2, 3, 4, -6]
|
||||
|
@ -2,7 +2,7 @@ function sieveOfEratosthenes (n) {
|
||||
/*
|
||||
* Calculates prime numbers till a number n
|
||||
* :param n: Number upto which to calculate primes
|
||||
* :return: A boolean list contaning only primes
|
||||
* :return: A boolean list containing only primes
|
||||
*/
|
||||
const primes = new Array(n + 1)
|
||||
primes.fill(true) // set all as true initially
|
||||
|
@ -21,14 +21,14 @@ const isValid = (board, row, col, k) => {
|
||||
return true
|
||||
}
|
||||
|
||||
const sodokoSolver = (data) => {
|
||||
const sudokuSolver = (data) => {
|
||||
for (let i = 0; i < 9; i++) {
|
||||
for (let j = 0; j < 9; j++) {
|
||||
if (data[i][j] === '.') {
|
||||
for (let k = 1; k <= 9; k++) {
|
||||
if (isValid(data, i, j, k)) {
|
||||
data[i][j] = `${k}`
|
||||
if (sodokoSolver(data)) {
|
||||
if (sudokuSolver(data)) {
|
||||
return true
|
||||
} else {
|
||||
data[i][j] = '.'
|
||||
@ -44,7 +44,7 @@ const sodokoSolver = (data) => {
|
||||
|
||||
// testing
|
||||
(() => {
|
||||
if (sodokoSolver(_board)) {
|
||||
if (sudokuSolver(_board)) {
|
||||
console.log(_board)
|
||||
}
|
||||
})()
|
||||
|
@ -1,19 +1,19 @@
|
||||
import { longestPalindromeSubsequence } from '../LongestPalindromicSubsequence'
|
||||
|
||||
describe('LongestPalindromicSubsequence', () => {
|
||||
it('expects to return 1 as longest pallindromic subsequence', () => {
|
||||
it('expects to return 1 as longest palindromic subsequence', () => {
|
||||
expect(longestPalindromeSubsequence('abcdefgh')).toBe(1)
|
||||
})
|
||||
|
||||
it('expects to return 4 as longest pallindromic subsequence', () => {
|
||||
it('expects to return 4 as longest palindromic subsequence', () => {
|
||||
expect(longestPalindromeSubsequence('bbbab')).toBe(4)
|
||||
})
|
||||
|
||||
it('expects to return 2 as longest pallindromic subsequence', () => {
|
||||
it('expects to return 2 as longest palindromic subsequence', () => {
|
||||
expect(longestPalindromeSubsequence('cbbd')).toBe(2)
|
||||
})
|
||||
|
||||
it('expects to return 7 as longest pallindromic subsequence', () => {
|
||||
it('expects to return 7 as longest palindromic subsequence', () => {
|
||||
expect(longestPalindromeSubsequence('racexyzcxar')).toBe(7)
|
||||
})
|
||||
})
|
||||
|
@ -33,7 +33,7 @@ function convexHull (points) {
|
||||
points.sort(compare)
|
||||
const p1 = points[0]; const p2 = points[pointsLen - 1]
|
||||
|
||||
// Divide Hull in two halfs
|
||||
// Divide Hull in two halves
|
||||
const upperPoints = []; const lowerPoints = []
|
||||
|
||||
upperPoints.push(p1)
|
||||
|
@ -2,7 +2,7 @@
|
||||
* Author: Samarth Jain
|
||||
* Dijkstra's Algorithm implementation in JavaScript
|
||||
* Dijkstra's Algorithm calculates the minimum distance between two nodes.
|
||||
* It is used to find the shortes path.
|
||||
* It is used to find the shortest path.
|
||||
* It uses graph data structure.
|
||||
*/
|
||||
|
||||
|
@ -2,8 +2,8 @@
|
||||
https://dev.to/rattanakchea/amazons-interview-question-count-island-21h6
|
||||
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.
|
||||
|
||||
two a dimensial grid map
|
||||
each element is going to represent a peice of land
|
||||
a two dimensional grid map
|
||||
each element is going to represent a piece of land
|
||||
1 is land,
|
||||
0 is water
|
||||
output a number which is the number of islands
|
||||
|
@ -9,11 +9,11 @@
|
||||
const CHAR_SIZE = 8
|
||||
|
||||
/**
|
||||
* Adds padding to binary/hex string represention
|
||||
* Adds padding to binary/hex string representation
|
||||
*
|
||||
* @param {string} str - string represention (binary/hex)
|
||||
* @param {string} str - string representation (binary/hex)
|
||||
* @param {int} bits - total number of bits wanted
|
||||
* @return {string} - string represention padding with empty (0) bits
|
||||
* @return {string} - string representation padding with empty (0) bits
|
||||
*
|
||||
* @example
|
||||
* pad("10011", 8); // "00010011"
|
||||
|
@ -20,11 +20,11 @@ const K = [
|
||||
]
|
||||
|
||||
/**
|
||||
* Adds padding to binary/hex string represention
|
||||
* Adds padding to binary/hex string representation
|
||||
*
|
||||
* @param {string} str - string represention (binary/hex)
|
||||
* @param {string} str - string representation (binary/hex)
|
||||
* @param {int} bits - total number of bits wanted
|
||||
* @return {string} - string represention padding with empty (0) bits
|
||||
* @return {string} - string representation padding with empty (0) bits
|
||||
*
|
||||
* @example
|
||||
* pad("10011", 8); // "00010011"
|
||||
@ -56,7 +56,7 @@ function chunkify (str, size) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates string represention of bits to th left
|
||||
* Rotates string representation of bits to th left
|
||||
*
|
||||
* @param {string} bits - string representation of bits
|
||||
* @param {int} turns - number of rotations to make
|
||||
|
@ -26,7 +26,7 @@ let LinearAlgebra;
|
||||
if (N === comps.length) {
|
||||
this.components = comps
|
||||
} else {
|
||||
throw new Error('Vector: invalide size!')
|
||||
throw new Error('Vector: invalid size!')
|
||||
}
|
||||
}
|
||||
} // end of constructor
|
||||
|
@ -2,7 +2,7 @@
|
||||
Modified from:
|
||||
https://github.com/TheAlgorithms/Python/blob/master/maths/binary_exponentiation.py
|
||||
|
||||
Explaination:
|
||||
Explanation:
|
||||
https://en.wikipedia.org/wiki/Exponentiation_by_squaring
|
||||
*/
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
/*
|
||||
Problem statement and Explanation : https://www.geeksforgeeks.org/check-if-a-number-is-a-krishnamurthy-number-or-not-2/
|
||||
|
||||
krishnamurthy number is a number the sum of the all fectorial of the all dights is equal to the number itself.
|
||||
krishnamurthy number is a number the sum of the all factorial of the all dights is equal to the number itself.
|
||||
145 => 1! + 4! + 5! = 1 + 24 + 120 = 145
|
||||
*/
|
||||
|
||||
// factorail utility method.
|
||||
// factorial utility method.
|
||||
const factorial = (n) => {
|
||||
let fact = 1
|
||||
while (n !== 0) {
|
||||
@ -18,7 +18,7 @@ const factorial = (n) => {
|
||||
/**
|
||||
* krishnamurthy number is a number the sum of the factorial of the all dights is equal to the number itself.
|
||||
* @param {Number} number a number for checking is krishnamurthy number or not.
|
||||
* @returns return correspond boolean vlaue, if the number is krishnamurthy number return `true` else return `false`.
|
||||
* @returns return correspond boolean value, if the number is krishnamurthy number return `true` else return `false`.
|
||||
* @example 145 => 1! + 4! + 5! = 1 + 24 + 120 = 145
|
||||
*/
|
||||
const CheckKishnamurthyNumber = (number) => {
|
||||
|
@ -4,7 +4,7 @@
|
||||
const digitSum = (num) => {
|
||||
// sum will store sum of digits of a number
|
||||
let sum = 0
|
||||
// while will run untill num become 0
|
||||
// while will run until num become 0
|
||||
while (num) {
|
||||
sum += num % 10
|
||||
num = parseInt(num / 10)
|
||||
|
@ -2,7 +2,7 @@
|
||||
Modified from:
|
||||
https://github.com/TheAlgorithms/Python/blob/master/maths/binary_exp_mod.py
|
||||
|
||||
Explaination:
|
||||
Explanation:
|
||||
https://en.wikipedia.org/wiki/Exponentiation_by_squaring
|
||||
*/
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Wikipedia: https://en.wikipedia.org/wiki/Monte_Carlo_method
|
||||
// Video Explaination: https://www.youtube.com/watch?v=ELetCV_wX_c
|
||||
// Video Explanation: https://www.youtube.com/watch?v=ELetCV_wX_c
|
||||
|
||||
const piEstimation = (iterations = 100000) => {
|
||||
let circleCounter = 0
|
||||
|
@ -2,7 +2,7 @@ const sieveOfEratosthenes = (n) => {
|
||||
/*
|
||||
* Calculates prime numbers till a number n
|
||||
* :param n: Number upto which to calculate primes
|
||||
* :return: A boolean list contaning only primes
|
||||
* :return: A boolean list containing only primes
|
||||
*/
|
||||
const primes = new Array(n + 1)
|
||||
primes.fill(true) // set all as true initially
|
||||
|
@ -17,7 +17,7 @@ function sumOfDigitsUsingString (number) {
|
||||
}
|
||||
|
||||
/*
|
||||
The input is divided by 10 in each iteraction, till the input is equal to 0
|
||||
The input is divided by 10 in each iteration, till the input is equal to 0
|
||||
The sum of all the digits is returned (The res variable acts as a collector, taking the remainders on each iteration)
|
||||
*/
|
||||
function sumOfDigitsUsingLoop (number) {
|
||||
|
@ -6,20 +6,20 @@ import {
|
||||
FibonacciMatrixExpo
|
||||
} from '../Fibonacci'
|
||||
|
||||
describe('Fibonanci', () => {
|
||||
it('should return an array of numbers for FibonnaciIterative', () => {
|
||||
describe('Fibonacci', () => {
|
||||
it('should return an array of numbers for FibonacciIterative', () => {
|
||||
expect(FibonacciIterative(5)).toEqual(
|
||||
expect.arrayContaining([1, 1, 2, 3, 5])
|
||||
)
|
||||
})
|
||||
|
||||
it('should return an array of numbers for FibonnaciRecursive', () => {
|
||||
it('should return an array of numbers for FibonacciRecursive', () => {
|
||||
expect(FibonacciRecursive(5)).toEqual(
|
||||
expect.arrayContaining([1, 1, 2, 3, 5])
|
||||
)
|
||||
})
|
||||
|
||||
it('should return number for FibonnaciRecursiveDP', () => {
|
||||
it('should return number for FibonacciRecursiveDP', () => {
|
||||
expect(FibonacciRecursiveDP(5)).toBe(5)
|
||||
})
|
||||
|
||||
@ -29,7 +29,7 @@ describe('Fibonanci', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('should return number for FibonnaciMatrixExpo', () => {
|
||||
it('should return number for FibonacciMatrixExpo', () => {
|
||||
expect(FibonacciMatrixExpo(0)).toBe(0)
|
||||
expect(FibonacciMatrixExpo(1)).toBe(1)
|
||||
expect(FibonacciMatrixExpo(2)).toBe(1)
|
||||
|
@ -33,12 +33,12 @@ const getCollatzSequenceLength = (num, seqLength) => {
|
||||
|
||||
const findLongestCollatzSequence = () => {
|
||||
let startingPointForLargestSequence = 1
|
||||
let largestSequnceLength = 1
|
||||
let largestSequenceLength = 1
|
||||
for (let i = 2; i < 1000000; i++) {
|
||||
const currentSequenceLength = getCollatzSequenceLength(i, 1)
|
||||
if (currentSequenceLength > largestSequnceLength) {
|
||||
if (currentSequenceLength > largestSequenceLength) {
|
||||
startingPointForLargestSequence = i
|
||||
largestSequnceLength = currentSequenceLength
|
||||
largestSequenceLength = currentSequenceLength
|
||||
}
|
||||
}
|
||||
return startingPointForLargestSequence
|
||||
|
@ -25,4 +25,4 @@ See our [directory](DIRECTORY.md).
|
||||
|
||||
## Algorithm Explanation
|
||||
|
||||
see our [wiki](https://github.com/TheAlgorithms/Javascript/wiki)
|
||||
See our [wiki](https://github.com/TheAlgorithms/Javascript/wiki).
|
||||
|
@ -15,7 +15,7 @@ function makeTable (str) {
|
||||
// case 1. the current character doesn't match the last character of the longest prefix
|
||||
while (maxPrefix > 0 && str.charAt(i) !== str.charAt(maxPrefix)) {
|
||||
// if that is the case, we have to backtrack, and try find a character that will be equal to the current character
|
||||
// if we reach 0, then we couldn't find a chracter
|
||||
// if we reach 0, then we couldn't find a character
|
||||
maxPrefix = table[maxPrefix - 1]
|
||||
}
|
||||
// case 2. The last character of the longest prefix matches the current character in `str`
|
||||
|
@ -54,11 +54,11 @@ function bucketSort (list, size) {
|
||||
}
|
||||
|
||||
// Testing
|
||||
const arrOrignal = [5, 6, 7, 8, 1, 2, 12, 14]
|
||||
// > bucketSort(arrOrignal)
|
||||
const arrOriginal = [5, 6, 7, 8, 1, 2, 12, 14]
|
||||
// > bucketSort(arrOriginal)
|
||||
// [1, 2, 5, 6, 7, 8, 12, 14]
|
||||
// Array before Sort
|
||||
console.log(arrOrignal)
|
||||
const arrSorted = bucketSort(arrOrignal)
|
||||
console.log(arrOriginal)
|
||||
const arrSorted = bucketSort(arrOriginal)
|
||||
// Array after sort
|
||||
console.log(arrSorted)
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @function Intosort (As implemented in STD C++ Lib)
|
||||
* The function performs introsort which is used in
|
||||
* C++ Standard LIbrary, the implemntation is inspired from]
|
||||
* C++ Standard LIbrary, the implementation is inspired from]
|
||||
* library routine itself.
|
||||
* ALGORITHM:
|
||||
* 1) It performs quicksort on array until the recursion depth
|
||||
@ -111,7 +111,7 @@ function introsort (array, compare) {
|
||||
*/
|
||||
quickSort(0, len, maxDepth)
|
||||
/**
|
||||
* A final checlk call to insertion sort
|
||||
* A final check call to insertion sort
|
||||
* on sorted array
|
||||
*/
|
||||
insertionSort(0, len)
|
||||
@ -140,7 +140,7 @@ function introsort (array, compare) {
|
||||
}
|
||||
/**
|
||||
* @function Helper function to quicksort
|
||||
* @param {Number} start the start of array segment to partitiion
|
||||
* @param {Number} start the start of array segment to partition
|
||||
* @param {Number} last one more than last index of the array segment
|
||||
* @param {Number} pivot the index of pivot to be used
|
||||
* @returns {Number} the index of pivot after partition
|
||||
|
@ -37,7 +37,7 @@ const quickSort = (inputList, low, high) => {
|
||||
|
||||
/**
|
||||
* Partition In Place method.
|
||||
* @param {number[]} partitionList list for partiting.
|
||||
* @param {number[]} partitionList list for partitioning.
|
||||
* @param {number} low lower index for partition.
|
||||
* @param {number} high higher index for partition.
|
||||
* @returns {number} `pIndex` pivot index value.
|
||||
|
@ -30,7 +30,7 @@ const Timsort = (array) => {
|
||||
/**
|
||||
* @function performs insertion sort on the partition
|
||||
* @param {Array} array array to be sorted
|
||||
* @param {Number} left left index of partiton
|
||||
* @param {Number} left left index of partition
|
||||
* @param {Number} right right index of partition
|
||||
*/
|
||||
|
||||
|
@ -14,24 +14,24 @@ const AlternativeStringArrange = (str1, str2) => {
|
||||
return 'Not string(s)'
|
||||
}
|
||||
|
||||
// output string vlaue.
|
||||
// output string value.
|
||||
let outStr = ''
|
||||
|
||||
// get first string length.
|
||||
const firstStringLength = str1.length
|
||||
// get second string length.
|
||||
const secondStringLength = str2.length
|
||||
// absolute length for oparetion.
|
||||
const absLenght = firstStringLength > secondStringLength ? firstStringLength : secondStringLength
|
||||
// absolute length for operation.
|
||||
const absLength = firstStringLength > secondStringLength ? firstStringLength : secondStringLength
|
||||
|
||||
// Iterate the character count until the absolute count is reached.
|
||||
for (let charCount = 0; charCount < absLenght; charCount++) {
|
||||
// If firstStringLength is lesser than the charCount it means they are able to re-arange.
|
||||
for (let charCount = 0; charCount < absLength; charCount++) {
|
||||
// If firstStringLength is lesser than the charCount it means they are able to re-arrange.
|
||||
if (charCount < firstStringLength) {
|
||||
outStr += str1[charCount]
|
||||
}
|
||||
|
||||
// If secondStringLength is lesser than the charCount it means they are able to re-arange.
|
||||
// If secondStringLength is lesser than the charCount it means they are able to re-arrange.
|
||||
if (charCount < secondStringLength) {
|
||||
outStr += str2[charCount]
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ const checkPalindrome = (str) => {
|
||||
if (str.length === 0) {
|
||||
return 'Empty string'
|
||||
}
|
||||
// Reverse only works with array, thus conevert the string to array, reverse it and convert back to string
|
||||
// Reverse only works with array, thus convert the string to array, reverse it and convert back to string
|
||||
// return as palindrome if the reversed string is equal to the input string
|
||||
const reversed = [...str].reverse().join('')
|
||||
return str === reversed ? 'Palindrome' : 'Not a Palindrome'
|
||||
|
@ -15,12 +15,12 @@ const levenshteinDistance = (a, b) => {
|
||||
.fill(null)
|
||||
.map(() => Array(a.length + 1).fill(null))
|
||||
|
||||
// Initialising first column:
|
||||
// Initializing first column:
|
||||
for (let i = 0; i <= a.length; i += 1) {
|
||||
distanceMatrix[0][i] = i
|
||||
}
|
||||
|
||||
// Initialising first row:
|
||||
// Initializing first row:
|
||||
for (let j = 0; j <= b.length; j += 1) {
|
||||
distanceMatrix[j][0] = j
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
// Given a sentence, return the most occuring word
|
||||
// Given a sentence, return the most occurring word
|
||||
|
||||
/**
|
||||
* @param {string} sentence - the sentence you want to find the most occuring word
|
||||
* @returns {string} - the most occuring word
|
||||
* @param {string} sentence - the sentence you want to find the most occurring word
|
||||
* @returns {string} - the most occurring word
|
||||
*
|
||||
* @example
|
||||
* - maxWord('lala lili lala'); // lala
|
||||
*/
|
||||
const maxWord = (sentence = '') => {
|
||||
if (typeof sentence !== 'string') {
|
||||
throw new TypeError('the param sould be string')
|
||||
throw new TypeError('the param should be string')
|
||||
}
|
||||
|
||||
if (!sentence) {
|
||||
|
@ -6,7 +6,7 @@ describe('Testing the maxWord function', () => {
|
||||
})
|
||||
it('get the max word', () => {
|
||||
const string = 'ba ba ba ba banana'
|
||||
const mostOccuringWord = maxWord(string)
|
||||
expect(mostOccuringWord).toBe('ba')
|
||||
const mostOccurringWord = maxWord(string)
|
||||
expect(mostOccurringWord).toBe('ba')
|
||||
})
|
||||
})
|
||||
|
@ -18,7 +18,7 @@ describe('checkIfPatternExists', () => {
|
||||
const SUT = checkIfPatternExists(text, pattern)
|
||||
expect(SUT).toBe(undefined)
|
||||
})
|
||||
it('expects to throw an error message when given inpuut is not a string', () => {
|
||||
it('expects to throw an error message when given input is not a string', () => {
|
||||
const text = 123444456
|
||||
const pattern = 123
|
||||
expect(() => checkIfPatternExists(text, pattern)).toThrow(
|
||||
|
@ -25,7 +25,7 @@ class BinaryTree {
|
||||
return this.traversal.toLocaleString()
|
||||
}
|
||||
|
||||
// Compputing the height of the tree
|
||||
// Computing the height of the tree
|
||||
getHeight (node) {
|
||||
if (node == null) {
|
||||
return 0
|
||||
|
Reference in New Issue
Block a user