hubot-business-cat icon indicating copy to clipboard operation
hubot-business-cat copied to clipboard

jargon could end up undefined

Open sr105 opened this issue 6 years ago • 1 comments

https://github.com/hubot-scripts/hubot-business-cat/blob/master/src/businesscat.coffee#L27

In removeTerm(), if a term is not found, it returns undefined due to the return being nested inside of the if [found]. Thus, if the last term in omittedJargon is not found, jargon will be set to undefined.

Possible fixes:

  • I think reducing the indent on the return will fix this.
  • Don't return anything and remove the jargon = from the omit line. removeTerm alters the incoming list.

Problem:

coffee> jargon = [1..5]
[ 1, 2, 3, 4, 5 ]
coffee> jargon = removeTerm(term, jargon) for term in [3, 99]
[ [ 1, 2, 4, 5 ], undefined ]
coffee> jargon
undefined

Possible solution 1:

------> removeTerm = (term, arrayToDeleteFrom) ->
.......   index = arrayToDeleteFrom.indexOf term
.......   if index > -1
.......     arrayToDeleteFrom.splice index, 1
.......   return arrayToDeleteFrom
[Function: removeTerm]
coffee> jargon = [1..5]
[ 1, 2, 3, 4, 5 ]
coffee> jargon = removeTerm(term, jargon) for term in [3, 99]
[ [ 1, 2, 4, 5 ], [ 1, 2, 4, 5 ] ]
coffee> jargon
[ 1, 2, 4, 5 ]
coffee>

Possible solution 2:

coffee> jargon = [1..5]
[ 1, 2, 3, 4, 5 ]
coffee> removeTerm(term, jargon) for term in [3, 99]
[ [ 1, 2, 4, 5 ], undefined ]
coffee> jargon
[ 1, 2, 4, 5 ]
coffee>

sr105 avatar Nov 15 '18 15:11 sr105

hi @sr105, thanks for pointing out this issue! I opened a PR here https://github.com/hubot-scripts/hubot-business-cat/pull/41 using your first solution if you want to take a look.

okize avatar Mar 11 '19 19:03 okize