Add External Scripts/Pens
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
// Impure case 1: even with the same input, the output is different each time due to Math.random() generated within the function (this is also the case with dates!)
var myAge = 29;
var randomlyOlder = (currentAge) => currentAge + parseInt((Math.random() * 10).toFixed(0));
console.log('Randomly Older: ' + randomlyOlder(myAge));
// Impure case 2: the output depends on a value defined outside of the function.
var yourAge = 19;
var addSomeYears = (years) => yourAge + years;
// Pure versions of the above:
// for inputs 29 and 10, the answer will always be 39 compared to the impure function above where, for input 20, the answer will vary depending on the value of yourAge.
var gettingOlder = (age, years) => age + years;
// If you still wanted to use a random number, you can determine that outside the function, and pass it in as the years parameter:
var random = parseInt((Math.random() * 10).toFixed(0));
console.log('More random aging: ' + gettingOlder(29, random));
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.