Passed
Pull Request — master (#1)
by Muhammad Dyas
02:04
created

src/helpers/option.ts   A

Complexity

Total Complexity 4
Complexity/F 2

Size

Lines of Code 18
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 8
mnd 2
bc 2
fnc 2
dl 0
loc 18
bpm 1
cpm 2
noi 0
c 0
b 0
f 0
rs 10
1
/**
2
 * Add a new option to the state(like DB)
3
 *
4
 * @param {string} option - the new option name
5
 * @param {object} state - the current message state
6
 * @param {string} creator - who add the new option
7
 * @returns {void} card
8
 */
9
export function addOptionToState(option, state, creator = '') {
10
  const choiceLength = state.choices.length;
11
  state.choices.push(option);
12
  if (state.choiceCreator === undefined) {
13
    state.choiceCreator = {[choiceLength]: creator};
14
  } else {
15
    state.choiceCreator[choiceLength] = creator;
16
  }
17
}
18