bradtraversy / traversy-js-challenges Goto Github PK
View Code? Open in Web Editor NEWChallenges & docs from JS Algorithms & Data Structures course
Challenges & docs from JS Algorithms & Data Structures course
I found one more small bug.
in 03-high-order-array-methods
> 04-highest-scoring-word
, the Constraints
in the readme state that the input string will only contain lowercase letters.
However, the run file uses the string highestScoringWord('Hello my name is xavier');
with an uppercase H
.
The file 06-hash-tables-maps-sets/13-add-get-values-method/get-values.test.js
should be renamed to 06-hash-tables-maps-sets/13-add-get-values-method/get-values-test.js
.
So basically replace the dot with a dash. Otherwise, Jest fails the test. This might confuse people when they try to test the first problems (i.e. "Hello World) and see an error despite their solution being correct.
In the video, Brad runs into a bug with the code and fixes it by replacing let maxSum = 0;
with let maxSum = -Infinity;
The problem is that the wrong code is still in the repo. Just need to replace it like in the video.
The file 06-hash-tables-maps-sets/13-add-get-values-method/get-values.test.js
should be renamed to 06-hash-tables-maps-sets/13-add-get-values-method/get-values-test.js
. Otherwise, it fails when running earlier tests.
This might be confusing to some newer developers.
I am getting error here (Screenshot Attached) while running the command npm test
There is a solution possible with format phone number using regexes and replacing groups. So whatever you put inside brackets, you can then reference in the replace clause using $1
$2
and so on.
Here is the code:
const formatPhoneNumber = (numbers) => numbers
.reduce((output, number) => output + number, '')
.replace(/([0-9]{3})([0-9]{3})([0-9]{4})/, '($1) $2-$3')
So I am first converting the numbers array into string using reduce
.
Then I am creating regex groups in the left side of replace
statement:
([0-9]{3})
means first 3 digits will be accessible via $1
([0-9]{3})
means next 3 digits will be accessible via $2
([0-9]{3})
means last 4 digits will be accessible via $3
Then you can reference it in the right side of replace
statement using ($1) $2-$3
.
In Valid Anagrams problem. the solution is not complete.
it is checking that frequencyCount1
is matching with frequencyCount2
but we also need to test frequencyCount2
is matching with frequencyCount1
. for example: if I run the test with const result = validAnagrams('app', 'ppax');
it returns true but it should be false.
In 04-recursion/02-unwinding/sum-up-to-test.js , there is no import statement for the sumUpTo() function.
Hence there is a error while testing, as sumUpTo is not defined in test file
https://github.com/bradtraversy/traversy-js-challenges/tree/main/01-basic-challenges-1/06-title-case
In the examples
titleCase("I'm a little tea pot"); // I'm A Little Tea Pot
titleCase('sHoRt AnD sToUt'); // Short And Stout
titleCase('HERE IS MY HANDLE HERE IS MY SPOUT'); // Here Is My Handle Here Is My Spout
It shows that we need to convert the first letter of each word to UpperCase and the rest to LowerCase.
https://github.com/bradtraversy/traversy-js-challenges/blob/main/01-basic-challenges-1/06-title-case/readme.md#solutions
In the first solution as well it is clearly converted toLowerCase
But in the second solution, only the first character is converted to upper case and rest remains the same.
So either the question and test-cases are wrong, or the examples and Solution 1 is wrong.
I got an error while trying to run a test in find-missing-letter-run.js
for the "Find the Missing Letter" challenge.
result = findMissingLetter(['a', 'b', 'c', 'f', 'g']);
As you can see, it's missing both the letters 'd' and 'e'. I believe you meant to only have one missing, right?
The current implementation of the validAnagrams function in the repository does not consider the length of the input strings when determining if they are anagrams. For example, it expects to return false but returns true in cases like validAnagrams("abcd", "abcde")
function validAnagrams(str1, str2) {
const freqCount1 = str1.split('').reduce((acc, char) => {
acc[char] = (acc[char] || 0) + 1;
return acc;
}, {});
const freqCount2 = str2.split('').reduce((acc, char) => {
acc[char] = (acc[char] || 0) + 1;
return acc;
}, {});
return Object.keys(freqCount1).every(
(char) => freqCount1[char] === freqCount2[char]
);
}
This function also needs to check the length of strings to be equal at the beginning:
if (str1.length !== str2.length) {
return false;
}
05-time-complexity/08-max-subarray-quadratic and 05-time-complexity/10-max-subarray-linear
For k2 = 4 the expected result should be -11 instead of -9.
In section 02-basic-chalanges-2
> 05-find-missing-letter
, the run file is missing 2 letters (d
and e
), rather than one
const findMissingLetter = require('./find-missing-letter');
result = findMissingLetter(['a', 'b', 'c', 'f', 'g']);
console.log(result);
A simple oversight, I'm sure. Loving the challenges, BTW!
The test as-is didn't cover faulty operator handling, so I came up with
// calculator.test.js
// Division
...
// Error case: Invalid operator
expect(() => calculator(num1, num2, "//")).toThrow("Invalid operator");
Adding the error throwing handling naturally requires the main file to throw an error in this case. I used the default for that:
function calculator(num1, num2, operator) {
switch (operator) {
case "+": return num1 + num2;
case "-": return num1 - num2;
case "*": return num1 * num2;
case "/": return num1 / num2;
default: throw new Error('Invalid operator');
}
}
This way, anything other than the operators throws an error. You're welcome to use it, if you choose.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ššš
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ā¤ļø Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.