Skip to content
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

nf seems to have wrong prototypes #6994

Open
2 of 17 tasks
IronBlood opened this issue Apr 27, 2024 · 3 comments
Open
2 of 17 tasks

nf seems to have wrong prototypes #6994

IronBlood opened this issue Apr 27, 2024 · 3 comments

Comments

@IronBlood
Copy link
Contributor

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

main branch

Web browser and version

No response

Operating system

No response

Steps to reproduce this

This is generally a report about the documentation and test cases.

From the reference, the prototypes for nf are:

  • nf(num, [left], [right])
  • nf(nums, [left], [right])

However, from the source code, especially in doNf(num, left, right), there isn't check of type left === 'undefined', nor a default value for left, so when calling leftPart = leftPart.padStart(left, '0'), left cannot be undefined.

Also in the test suite of p5.prototype.nf, test cases are missing:

  • result = nf(1234), if left is optional
  • result = nf([1234, 3.141516, 3.141516e-2], 2) for an array of numbers to format
@IronBlood IronBlood added the Bug label Apr 27, 2024
Copy link

welcome bot commented Apr 27, 2024

Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms. Thank you!

@Akhilbisht798
Copy link

Hey, I am intrested in this isssue. As you said here.

 However, from the source code, especially in doNf(num, left, right), there isn't check of type left === 'undefined', nor a default value for left, so when calling leftPart = leftPart.padStart(left, '0'), left cannot be undefined

did you meant that left can be undefined because that will make more sense if i am not wrong.

@Akhilbisht798
Copy link

I can be wrong in this but i think
p5._validateParameters('nf', arguments);
Here the arguments are being checked so that they are always correct or something of that sort.
But for test cases i think you are right we should have a test for array and test for only right argument.

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

No branches or pull requests

2 participants