nafets.io first post
This is my obligatory first post. I will be writing things here in this blog.
Code #
I'll mostly write code related things here.
Mostly about serverless.
Using Javascript,
// get stefan's first post
const POSTS = [{ id: 1, title: "first post" }]
function getPost(id=null) {
return POSTS.find(post => id === post.id)
}
console.log(getPost(1));
Python,
# get stefan's first post
POSTS = [{ 'id': 1, 'title': 'first post' }]
def get_post(id=None):
return next((post for post in POSTS if id == post.get('id')), None)
print(get_post(id=1))
and Ruby.
# get stefan's first post
POSTS = [{ :id => 1, :title => 'first post' }]
def get_post(id)
POSTS.find { |post| post[:id] == id }
end
puts get_post(1)