diff --git a/Backtracking/SumOfSubset.js b/Backtracking/SumOfSubset.js index 16573e5fab..5676569955 100644 --- a/Backtracking/SumOfSubset.js +++ b/Backtracking/SumOfSubset.js @@ -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] }) diff --git a/Bit-Manipulation/BinaryCountSetBits.js b/Bit-Manipulation/BinaryCountSetBits.js index bb16afe949..3fcb9d619c 100644 --- a/Bit-Manipulation/BinaryCountSetBits.js +++ b/Bit-Manipulation/BinaryCountSetBits.js @@ -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 } diff --git a/Ciphers/KeyFinder.js b/Ciphers/KeyFinder.js index 8a66facc65..1a4059e335 100644 --- a/Ciphers/KeyFinder.js +++ b/Ciphers/KeyFinder.js @@ -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 } diff --git a/Conversions/DateDayDifference.js b/Conversions/DateDayDifference.js index 43a3a9264c..4cf900089d 100644 --- a/Conversions/DateDayDifference.js +++ b/Conversions/DateDayDifference.js @@ -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 || diff --git a/Conversions/DateToDay.js b/Conversions/DateToDay.js index ed65d18548..52d3be8522 100644 --- a/Conversions/DateToDay.js +++ b/Conversions/DateToDay.js @@ -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) { diff --git a/Conversions/RailwayTimeConversion.js b/Conversions/RailwayTimeConversion.js index f3d30fdef0..65f9836c3c 100644 --- a/Conversions/RailwayTimeConversion.js +++ b/Conversions/RailwayTimeConversion.js @@ -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 */ diff --git a/Conversions/TitleCaseConversion.js b/Conversions/TitleCaseConversion.js index 44967d1249..82ff81ae16 100644 --- a/Conversions/TitleCaseConversion.js +++ b/Conversions/TitleCaseConversion.js @@ -2,7 +2,7 @@ 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 regarless of length. + is taken where all words are capitalized regardless of length. */ /** @@ -12,7 +12,7 @@ */ const titleCaseConversion = (inputString) => { if (inputString === '') return '' - // Extact all space seprated string. + // Extract all space separated string. const stringCollections = inputString.split(' ').map(word => { let firstChar = '' // Get the [ASCII](https://en.wikipedia.org/wiki/ASCII) character code by the use charCodeAt method. diff --git a/Data-Structures/Linked-List/CycleDetection.js b/Data-Structures/Linked-List/CycleDetection.js index 910fe2214f..ba33cd0c4a 100644 --- a/Data-Structures/Linked-List/CycleDetection.js +++ b/Data-Structures/Linked-List/CycleDetection.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/ */ diff --git a/Data-Structures/Linked-List/RotateListRight.js b/Data-Structures/Linked-List/RotateListRight.js index 8acc7c767c..5fbdc913e4 100644 --- a/Data-Structures/Linked-List/RotateListRight.js +++ b/Data-Structures/Linked-List/RotateListRight.js @@ -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/ */ diff --git a/Data-Structures/Tree/AVLTree.js b/Data-Structures/Tree/AVLTree.js index 0c72ce3653..fc48f470fc 100644 --- a/Data-Structures/Tree/AVLTree.js +++ b/Data-Structures/Tree/AVLTree.js @@ -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 */ diff --git a/Data-Structures/Tree/Trie.js b/Data-Structures/Tree/Trie.js index 61b4f03c17..4dad3d316c 100644 --- a/Data-Structures/Tree/Trie.js +++ b/Data-Structures/Tree/Trie.js @@ -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,11 +79,11 @@ 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 diff --git a/Dynamic-Programming/KadaneAlgo.js b/Dynamic-Programming/KadaneAlgo.js index 14ac0b18e4..1e275dd096 100644 --- a/Dynamic-Programming/KadaneAlgo.js +++ b/Dynamic-Programming/KadaneAlgo.js @@ -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] diff --git a/Dynamic-Programming/SieveOfEratosthenes.js b/Dynamic-Programming/SieveOfEratosthenes.js index 1e0a2e2b21..b6b71a1959 100644 --- a/Dynamic-Programming/SieveOfEratosthenes.js +++ b/Dynamic-Programming/SieveOfEratosthenes.js @@ -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 diff --git a/Dynamic-Programming/tests/LongestPalindromicSubsequence.test.js b/Dynamic-Programming/tests/LongestPalindromicSubsequence.test.js index d68b392e97..bf5267acb9 100644 --- a/Dynamic-Programming/tests/LongestPalindromicSubsequence.test.js +++ b/Dynamic-Programming/tests/LongestPalindromicSubsequence.test.js @@ -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) }) }) diff --git a/Geometry/ConvexHullGraham.js b/Geometry/ConvexHullGraham.js index 3041663477..756121fb5a 100644 --- a/Geometry/ConvexHullGraham.js +++ b/Geometry/ConvexHullGraham.js @@ -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) diff --git a/Graphs/Dijkstra.js b/Graphs/Dijkstra.js index 159b19ad05..41bacd71dc 100644 --- a/Graphs/Dijkstra.js +++ b/Graphs/Dijkstra.js @@ -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. */ diff --git a/Graphs/NumberOfIslands.js b/Graphs/NumberOfIslands.js index 1f8627fcdc..51a447dd09 100644 --- a/Graphs/NumberOfIslands.js +++ b/Graphs/NumberOfIslands.js @@ -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 diff --git a/Hashes/SHA1.js b/Hashes/SHA1.js index b257a4301a..864ca392a8 100644 --- a/Hashes/SHA1.js +++ b/Hashes/SHA1.js @@ -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" diff --git a/Hashes/SHA256.js b/Hashes/SHA256.js index 9820981b8e..d47dfb03ee 100644 --- a/Hashes/SHA256.js +++ b/Hashes/SHA256.js @@ -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 diff --git a/Linear-Algebra/src/la_lib.js b/Linear-Algebra/src/la_lib.js index 41f99a3078..72d8473e8c 100644 --- a/Linear-Algebra/src/la_lib.js +++ b/Linear-Algebra/src/la_lib.js @@ -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 diff --git a/Maths/BinaryExponentiationRecursive.js b/Maths/BinaryExponentiationRecursive.js index 0830f2bc64..6ff1ecbb60 100644 --- a/Maths/BinaryExponentiationRecursive.js +++ b/Maths/BinaryExponentiationRecursive.js @@ -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 */ diff --git a/Maths/CheckKishnamurthyNumber.js b/Maths/CheckKishnamurthyNumber.js index bb283e68eb..d030fff846 100644 --- a/Maths/CheckKishnamurthyNumber.js +++ b/Maths/CheckKishnamurthyNumber.js @@ -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) => { diff --git a/Maths/DigitSum.js b/Maths/DigitSum.js index 792915d606..e4a93d5bbc 100644 --- a/Maths/DigitSum.js +++ b/Maths/DigitSum.js @@ -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) diff --git a/Maths/ModularBinaryExponentiationRecursive.js b/Maths/ModularBinaryExponentiationRecursive.js index b8374bd175..434215c358 100644 --- a/Maths/ModularBinaryExponentiationRecursive.js +++ b/Maths/ModularBinaryExponentiationRecursive.js @@ -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 */ diff --git a/Maths/PiApproximationMonteCarlo.js b/Maths/PiApproximationMonteCarlo.js index be7f754e4a..08849b5475 100644 --- a/Maths/PiApproximationMonteCarlo.js +++ b/Maths/PiApproximationMonteCarlo.js @@ -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 diff --git a/Maths/SieveOfEratosthenes.js b/Maths/SieveOfEratosthenes.js index 9c6b4b9110..e6e77b2673 100644 --- a/Maths/SieveOfEratosthenes.js +++ b/Maths/SieveOfEratosthenes.js @@ -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 diff --git a/Maths/SumOfDigits.js b/Maths/SumOfDigits.js index 859ef378b2..e076be7a56 100644 --- a/Maths/SumOfDigits.js +++ b/Maths/SumOfDigits.js @@ -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) { diff --git a/Maths/test/Fibonacci.test.js b/Maths/test/Fibonacci.test.js index 30b7ba6960..bccd799be9 100644 --- a/Maths/test/Fibonacci.test.js +++ b/Maths/test/Fibonacci.test.js @@ -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) diff --git a/Project-Euler/Problem014.js b/Project-Euler/Problem014.js index 62a2974ec0..0331837d09 100644 --- a/Project-Euler/Problem014.js +++ b/Project-Euler/Problem014.js @@ -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 diff --git a/Search/StringSearch.js b/Search/StringSearch.js index 3cd9c1e3e4..614575107c 100644 --- a/Search/StringSearch.js +++ b/Search/StringSearch.js @@ -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` diff --git a/Sorts/BucketSort.js b/Sorts/BucketSort.js index 9423c4c104..f05eacd76e 100644 --- a/Sorts/BucketSort.js +++ b/Sorts/BucketSort.js @@ -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) diff --git a/Sorts/IntroSort.js b/Sorts/IntroSort.js index 57edb4e8d2..01d3c449d7 100644 --- a/Sorts/IntroSort.js +++ b/Sorts/IntroSort.js @@ -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 diff --git a/Sorts/QuickSortRecursive.js b/Sorts/QuickSortRecursive.js index 1ab3f4a8eb..fe0cfae848 100644 --- a/Sorts/QuickSortRecursive.js +++ b/Sorts/QuickSortRecursive.js @@ -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. diff --git a/Sorts/TimSort.js b/Sorts/TimSort.js index 04c209f0f6..07556404be 100644 --- a/Sorts/TimSort.js +++ b/Sorts/TimSort.js @@ -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 */ diff --git a/String/AlternativeStringArrange.js b/String/AlternativeStringArrange.js index 6ff151f7d9..9b722a1f9e 100644 --- a/String/AlternativeStringArrange.js +++ b/String/AlternativeStringArrange.js @@ -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] } diff --git a/String/CheckPalindrome.js b/String/CheckPalindrome.js index cca2620a6c..a717ccd5f4 100644 --- a/String/CheckPalindrome.js +++ b/String/CheckPalindrome.js @@ -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' diff --git a/String/LevenshteinDistance.js b/String/LevenshteinDistance.js index acb09a529d..428e712653 100644 --- a/String/LevenshteinDistance.js +++ b/String/LevenshteinDistance.js @@ -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 } diff --git a/String/MaxWord.js b/String/MaxWord.js index c3ac637eaa..78199e3e9f 100644 --- a/String/MaxWord.js +++ b/String/MaxWord.js @@ -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) { diff --git a/String/test/MaxWord.test.js b/String/test/MaxWord.test.js index 8a5852ad6f..417f1232d5 100644 --- a/String/test/MaxWord.test.js +++ b/String/test/MaxWord.test.js @@ -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') }) }) diff --git a/String/test/PatternMatching.test.js b/String/test/PatternMatching.test.js index d0eab80b6f..aff4e70d83 100644 --- a/String/test/PatternMatching.test.js +++ b/String/test/PatternMatching.test.js @@ -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( diff --git a/Trees/BreadthFirstTreeTraversal.js b/Trees/BreadthFirstTreeTraversal.js index f81cf24e63..b9195144de 100644 --- a/Trees/BreadthFirstTreeTraversal.js +++ b/Trees/BreadthFirstTreeTraversal.js @@ -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