This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
1
Javascript Multiply, Exponent, Factorial, and Fibonacci Sequence Functions using only an Add function and no Operators
Post Flair (click to view more posts with a particular flair)
Post Body
I found a challenge where I have to create Multiply, Exponent, Factorial, and Fibonacci Sequence functions without operators/built in functions other than this block of code
function add(x, y) {
return (sum = x y);
}
So far, I only know how to do them using recursive functions with the (-) operator but that won't be accepted. I am completely lost as to how to go about this. The hint was to use a loop. We also cannot use or --
This is what I have so far but they don't meet the criteria.
function multiply(x, y) {
let n = x;
for (let i = 1; i < y; i = 1) x = n;
return x;
}
function exponent(x, n) {
if (n === 0) {
return 1;
} else {
return multiply(x, exponent(x, n - 1));
}
}
function factorial(x) {
if (x === 0) {
return 1;
} else {
return multiply(x, factorial(x - 1));
}
}
function fibonacci(n) {
if (n <= 1 || n === NaN || n % 1 !== 0) {
return 1;
} else {
return fibonacci(n - 1) fibonacci(n - 2);
}
Author
Account Strength
100%
Account Age
5 years
Verified Email
Yes
Verified Flair
No
Total Karma
9,114
Link Karma
553
Comment Karma
8,165
Profile updated: 2 days ago
Posts updated: 1 month ago
Subreddit
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 3 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnprogra...