christopherxc avatar

#100DaysOfCode Day 3

christopherxc

Published: 12 May 2018 › Updated: 12 May 2018#100DaysOfCode Day 3

#100DaysOfCode Day 3

Untitled.jpg

Hey everyone, today has been another day with not much actual code work done but a lot more theory then usual. I know the whole idea of this challenge is to code every single day, but seeing as I am pressed for time, some theory will defiantly do.

Moving on, we have a somewhat hack day at work today, and I was paired up wit hone of our backend developers to get a crash course on Arrays. I had to make an array of 10 values which I wrote in the following way.

a = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]

While this code is perfectly valid and will work, it's not that easy to write or to change. Say if I wanted to make the array 20 values in length. It took me a whiletenbut my college helped me get the following to build a better array.

a = new Array(10).fill().map((v, i, a) => {return i+1})

So let's break down whats going on here. I'm defining a new Array with 10 values. I use fill to put something into the array and I use map to put something in there.
Map will take three arguments. Value, index and array. Buy using the function return i+1 I can increment through the array and get an output of the numbers 1 - 20.

Well, hope everyone enjoied this post.

And remember, keep coding 🤓

Leave #100DaysOfCode Day 3 to:

Written by

Amature Programmer | Rock Climber | Bloger

Read more #programming posts


Best Posts From christopherxc

We have not curated any of christopherxc's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From christopherxc