Meta_Data - 9 months ago 46

Javascript Question

This is a python code to create a dictionary and update it with standard mathematical functions. How can I do the same in javascript?

`import math`

Env = dict # An environment is a mapping of {variable: value}

env = Env()

env.update(vars(math)) # sin, cos, sqrt, pi, ..

Answer Source

You can read properties of `Math`

with `getOwnPropertyNames`

object and then reduce it:

```
const dict = {};
Object.getOwnPropertyNames(Math).reduce((r, k) => {
r[k] = Math[k];
return r;
}, dict);
```