You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
915 B

## Find Expression
### Instructions
Create a function named `findExpression` that takes a `number` as parameter and returns a `string`.
- 2 constant variables will be made available to your function: `add4` and `mul2`.
- Your goal is to try to find a sequence, starting from the number 1, and repeatedly either adding 4 or multiplying by 2, to produce the number given as a parameter.
- If the number can not be reached you should return `undefined`
For example, for the number `8`, you must first multiply by 2 twice, and then add 4. Your function should return something like: `1 *2 *2 +4`.
### Notions
- [Loops](https://nan-academy.github.io/js-training/examples/loops.js)
- [Recursion](https://nan-academy.github.io/js-training/examples/recursion.js)
### Code provided
> The provided code will be added to your solution, and does not need to be submitted.
```js
const add4 = '+4'
const mul2 = '*2'
```