Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Update Happy_Number.js #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
ignacio-chiazzo merged 1 commit into ignacio-chiazzo:master from Alucard2169:patch-2
Feb 12, 2024

Conversation

@Alucard2169
Copy link
Contributor

@Alucard2169 Alucard2169 commented Feb 11, 2024

Added base case check for Happy number problem.


About the fix.

7 Is also considered a Happy number, previously the code was checking if the array length is 1 and n was 1 then return true else false.

Copy link
Owner

@ignacio-chiazzo ignacio-chiazzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi thanks for contributing.

I think it's enough to check just for 1 since 7 will eventually hit n === 1. I like the example, we can merge that 👍.

let splitNumber = strNumber.split("");
if(splitNumber.length <= 1){
return (n <=1)? true:false;
return (n ===1||n===7)? true:false;
Copy link
Owner

@ignacio-chiazzo ignacio-chiazzo Feb 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we'd need to check for 7 since it's already covered by n===1.

Suggested change
return (n === 1||n===7)? true:false;
return n === 1;

Copy link
Contributor Author

@Alucard2169 Alucard2169 Feb 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
Thanks for getting back to me, the thing is the first if condition checks whether the array's length is 1 or not,
in this case if the array has only 7 then it would be true, and since it is to return true if n===1 it would return false.

I have added some screenshots for tests please feel free to check them.

Copy link
Owner

@ignacio-chiazzo ignacio-chiazzo Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohhhh true! Nice catch. We need to list all happy numbers that are less than 10.

let splitNumber = strNumber.split("");
if(splitNumber.length <= 1){
return (n <=1)? true:false;
return (n ===1||n===7)? true:false;
Copy link
Owner

@ignacio-chiazzo ignacio-chiazzo Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohhhh true! Nice catch. We need to list all happy numbers that are less than 10.

@ignacio-chiazzo ignacio-chiazzo merged commit 2b375b0 into ignacio-chiazzo:master Feb 12, 2024
Copy link
Owner

Thank you @Alucard2169

Copy link
Contributor Author

No problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ignacio-chiazzo ignacio-chiazzo ignacio-chiazzo approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /