An Interest In:
Web News this Week
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
- April 13, 2024
June 14, 2022 01:10 pm GMT
Original Link: https://dev.to/marmeladze/mental-paralysis-in-an-interview-again-19h4
yet another fail
I weren't able to write that code during an interview. I've been asked to scrape unique 200 posts from a json feed.
require 'net/http'require 'json'start_url = "https://url-to-json.feed"posts = []loop do body = JSON.parse(Net::HTTP.get(URI(start_url))) next_page = body["paging"]["next"] body["data"].each do |new_post| id_exists = posts.detect {|post| post["id"] == new_post["id"] } unless id_exists posts << new_post end end url = next_page if posts.count > 199 break endend
Instead of that dumb and simple 15 lines of code, I started to create functions, pipe them each other, do some bullshit abstractions, and finally fucked up.
Original Link: https://dev.to/marmeladze/mental-paralysis-in-an-interview-again-19h4
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To