Completed
Push — master ( 57c78c...4fcad4 )
by Muhammad Dyas
15s queued 13s
created

src/helpers/option.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 20
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 9
mnd 1
bc 1
fnc 1
dl 0
loc 20
rs 10
bpm 1
cpm 2
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A option.ts ➔ addOptionToState 0 16 2
1
import {PollState} from './interfaces';
2
3
/**
4
 * Add a new option to the state(like DB)
5
 *
6
 * @param {string} option - the new option name
7
 * @param {object} state - the current message state
8
 * @param {string} creator - who add the new option
9
 * @returns {void} card
10
 */
11
export function addOptionToState(option: string, state: PollState, creator = '') {
12
  const choiceLength = state.choices.length;
13
  state.choices.push(option);
14
  if (state.choiceCreator === undefined) {
15
    state.choiceCreator = {[choiceLength]: creator};
16
  } else {
17
    state.choiceCreator[choiceLength] = creator;
18
  }
19
}
20