Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 14, 2022 01:10 pm GMT

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:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To