Hello I am not a ruby developer how I can pick random posts to show them like only 5 posts
I am trying to get the last post only with the picture. I success with it :) github.com/OmarElKhatibCS
The easiest way is to call sample(n) method on your posts where n is number of random posts you want to pick.
sample(n)
posts = JSON.parse(response.body).sample(5).map do |article|
It works with any array.
[1, 2, 3, 4, 5].sample(3) #=> 3, 1, 5 [1, 2, 3, 4, 5].sample(3) #=> 5, 4, 1 [1, 2, 3, 4, 5].sample(3) #=> 2, 4, 3
I will take it in consideration if I need to implement it , I edit it to get last post only with picture. Thanks for the script <3
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hello I am not a ruby developer how I can pick random posts to show them like only 5 posts
I am trying to get the last post only with the picture.
I success with it :)
github.com/OmarElKhatibCS
The easiest way is to call
sample(n)
method on your posts where n is number of random posts you want to pick.It works with any array.
I will take it in consideration if I need to implement it , I edit it to get last post only with picture. Thanks for the script <3