Sobes.tech
Back to tasks
Junior — Senior
23

Refactor the add function to make it pure

Get help with live coding in real time with Sobes Copilot
Task condition

The task is to clean up the add function by removing everything that violates the principles of a pure function.

let x = 2;

const add = async (params, y) => {
  params.value = y;
  y += y + Math.random(params.value);
  x += y;

  console.log('doubling', x);

  const { data } = await axios({ method: 'get', url: '/' });

  const elem = document.getElementById('elem');
  const width = elem.getBoundingClientRect().width;

  return x + data + width;
};

add({ value: 4 }, 1);