Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jargon could end up undefined #39

Open
sr105 opened this issue Nov 15, 2018 · 1 comment
Open

jargon could end up undefined #39

sr105 opened this issue Nov 15, 2018 · 1 comment

Comments

@sr105
Copy link

sr105 commented Nov 15, 2018

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>
@okize
Copy link
Member

okize commented Mar 11, 2019

hi @sr105, thanks for pointing out this issue! I opened a PR here #41 using your first solution if you want to take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants