Is a function that calls Math.random() pure?

后端 未结 9 1597
[愿得一人]
[愿得一人] 2021-01-30 15:30

Is the following a pure function?

function test(min,max) {
   return  Math.random() * (max - min) + min;
}

My understanding is that a pure func

9条回答
  •  执念已碎
    2021-01-30 15:59

    Pure functions always return the same value for same input. Pure functions are predictable and are referential transparent which means that we can replace the function call with the output returned and it will not change the working of the program.

    https://github.com/MostlyAdequate/mostly-adequate-guide/blob/master/ch3.md

提交回复
热议问题