Skip to content

Commit

Permalink
Use getRandomElement function
Browse files Browse the repository at this point in the history
  • Loading branch information
mfix22 authored and briandennis committed Jun 7, 2018
1 parent 203eac1 commit 251eaf9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/helpers/notifier/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,24 @@ function notify ({ didSucceed, operation }) {
}

function genInfo (didSucceed, operation) {
const index = getIndex()
const operationText = operation === MERGE ? 'Merge' : 'Conversion'

if (didSucceed) {
return {
title: `${operationText} complete!`,
body: text.success[index],
body: getRandomElement(text.success),
icon: `${imgPath}/success.png`
}
}

return {
title: `Oh no! ${operationText} failed.`,
body: text.failure[index],
body: getRandomElement(text.failure),
icon: `${imgPath}/failure.png`
}
}

function getIndex () {
function getRandomElement (array) {
const rnd = Math.random()
return Math.floor(rnd * text.messageCount)
return array[Math.floor(rnd * array.length)]
}
3 changes: 1 addition & 2 deletions src/helpers/notifier/text.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"messageCount": 5,
"success": [
"Your images are done a'brewin.",
"The transmutation was a success.",
Expand All @@ -14,4 +13,4 @@
"Another deception of the photo sorcerer.",
"The night is dark and full of terrors."
]
}
}

0 comments on commit 251eaf9

Please sign in to comment.