0

I have three functions structured in the following way:

const func = (arr) => {
  var ch = {};
  arr.map(ar => {
         ar.stage_executions.map((s) => {
        ch[s.stage.name] = [];
      })
  })
  return ch;
}

const func2 = (arr) => {
  var all = func(arr);
  for(var k in all) {
    arr.map((ar) => {
      ar.stage_executions.map((st) => {
        if (st.stage.name === k) {
          all[k].push(st.stage.name, st.duration_millis)
        }
      })
    })
  }
  return all;
}

const func3 = (arr) => {
  const all = func2(arr);
  for(var key in all) {
    all[key] = [...new Set(all[key])]
  }
  return all;
}

console.log(func3(job_execs))

I want to convert these into functions into methods that look like the rest of my vue.js methods.

example:

func: function() {
  return all
},

How do I do I convert my methods to look like the function above?

benjaminadon
  • 143
  • 3
  • 13
  • 2
    Genuine question: I don't see you relying on `this` in any of these functions: why are you using arrow functions instead of normal named functions? Also, [don't use `for ... in ...`](https://stackoverflow.com/questions/500504/why-is-using-for-in-with-array-iteration-a-bad-idea) with arrays – Mike 'Pomax' Kamermans Aug 28 '19 at 21:58

1 Answers1

0

You can just remove the arrow and add the function keyword to the beginning as you don't use 'this' in any of them From this: let name =() => {} to function name() {}