Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Fix for #100 - calculate random index for array
Browse files Browse the repository at this point in the history
We want to get random tweet ID to retweet for indexing into the array data.statuses, so  desired range for random number is [0..data.statuses.length-1]
 see function getRandomIntInclusive at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
  • Loading branch information
pabrams authored Sep 5, 2017
1 parent def82a3 commit cb18cef
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/api/retweet.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ const retweet = () => {
if (err) {
console.log('ERRORDERP: Cannot Search Tweet!, Description here: ', err)
} else {
// grab tweet ID to retweet
const rando = Math.floor(Math.random() * param.searchCount) + 1
// grab random tweet ID to retweet - desired range for random number is [0..data.statuses.length-1]
const rando = Math.floor(Math.random() * data.statuses.length);
let retweetId

try {
retweetId = data.statuses[rando].id_str
} catch (e) {
console.log('ERRORDERP: Cannot assign retweeID')
console.log('ERRORDERP: Cannot assign retweeID; exception message: ' + e.message);
return
}

Expand Down

0 comments on commit cb18cef

Please sign in to comment.