这是indexloc提供的服务,不要输入任何密码
Skip to content

Add isEven snippet to check if a number is a valid even integer #2122

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

Closed
wants to merge 3 commits into from

Conversation

Varnika060306
Copy link

What does this snippet do?

Checks if a given input is both:

  • An integer
  • Divisible by 2 (i.e., even)

This is useful to avoid edge cases with floats (like 4.0) or strings ("6").


✅ Preview

const isEven = num => Number.isInteger(num) && num % 2 === 0;

isEven(4);      // true (valid even integer)
isEven(7);      // false (odd integer)
isEven(2.5);    // false (not an integer)
isEven("6");    // false (string, not number)

📌 Why is this useful?

  • Safer and more robust check for even numbers.
  • Works well with user inputs, form validation, APIs, etc.
  • Avoids bugs from non-integer inputs like strings or floats.

📅 Date Modified

2025-07-23

feat(snippet): Add isEven utility function


Signed-off-by: Varnika <varnika147btit24@igdtuw.ac.in>
fix(snippet): correct metadata keys and formatting

Signed-off-by: Varnika <varnika147btit24@igdtuw.ac.in>
Added robust isEven utility with integer check and detailed explanation


Signed-off-by: Varnika <varnika147btit24@igdtuw.ac.in>
@github-actions github-actions bot added js Related to JavaScript content. snippet Related to snippets. content Changes to content. labels Jul 23, 2025
@Varnika060306
Copy link
Author

Hi maintainers 👋 I’ve submitted this snippet aligned with your guidelines. Happy to make any requested changes. Thanks for taking the time to review it!

@Chalarangelo
Copy link
Owner

Please read THE ENTIRETY of the guidelines, i.e.:

@Chalarangelo Chalarangelo added duplicate This issue has been brought up before. invalid Not an issue. labels Jul 24, 2025
Repository owner locked and limited conversation to collaborators Jul 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
content Changes to content. duplicate This issue has been brought up before. invalid Not an issue. js Related to JavaScript content. snippet Related to snippets.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants