JSFiddle - React, Tailwind, and code Playground

by Mariya_Korotkova

JavaScript

/* Task 1 */

/* function multiplier(x) {
return function(y) {
return x*y;
}
}

function processData(input) {
const waterWeight = multiplier(1000);
const mercuryWeight = multiplier(1355);
const oilWeight = multiplier(900);

console.log("Weight of " + input + " metric cube of water = " + waterWeight(input) + " kg");
console.log("Weight of " + input + " metric cube of mercury = " + mercuryWeight(input) + " kg");
console.log("Weight of " + input + " metric cube of oil = " + oilWeight(input) + " kg");
}

processData(100);
 */
/* Task 2 */
/* 
const getRandomNumber = makeRandomFn([1, 2, 100, 34, 45, 556, 33])

function makeRandomFn(arr) {
return function() {
return arr[Math.floor(Math.random() * arr.length)];
}
}
console.log(getRandomNumber()) // 556
console.log(getRandomNumber()) // 100
console.log(getRandomNumber()) // 2 */


/* Task 3 */

const getRandomNumber = makeRandomFn(1, 2, 100, 34, 45, 556, 33);

const getRandomNumberArr = makeRandomFn([1, 2, 100, 34, 45, 556, 33]);

function makeRandomFn(arg) {
let args = Array.isArray(arg) ? arg : arguments;
return () => {
return args[Math.floor(Math.random() * args.length)];

} 


}

console.log(getRandomNumber()) // 556
console.log(getRandomNumber()) // 100
console.log('ARR', getRandomNumberArr()) // 2
console.log(getRandomNumberArr()) // 2 */