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

Possible issue in function F #2

Open
jmetz opened this issue Apr 18, 2023 · 1 comment
Open

Possible issue in function F #2

jmetz opened this issue Apr 18, 2023 · 1 comment

Comments

@jmetz
Copy link

jmetz commented Apr 18, 2023

Firstly great work! I was trying to understand your code, and if I've understood correctly your function F might not be working as you intended, though perhaps it doesn't matter 🤷

Your code is :

function F(L,K){
	x = parseInt(L);
	k = parseInt(K);
	temp = ""+x*x*x*K*3+23*K*K*x*x*x+K*(x+K)+3;
	return temp.slice(4,10);
};

(https://github.com/pballett/whatfreewords/blob/master/index.html#L40-L45)

and specifically where you assign temp, you are doing an odd mix of numerical and string ops - basically the + operations are all doing string concatenation, as you operate on K and not k (perhaps you meant to use k? At the moment it's not used at all).

I would recommend changing to the following which I tested locally and also works:

function F(L,K){
	x = parseInt(L);
	k = parseInt(K);
	temp = x*x*x*k*3+23*k*k*x*x*x+k*(x+k)+3;
	return (""+temp).slice(4,10);
};

Here as you can see I operate on k (lowercase), and the assignment to temp returns a number, not a string. That is then coerced to a string on the following line before being sliced and returned.

@pballett
Copy link
Owner

Hey, great catch. Yeah that's a typo, which I suppose I never noticed because F is essentially arbitrary anyway. Thanks again.

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

No branches or pull requests

2 participants