___|  _ \   |  |    |   |_ _|\ \     / ____|
 |     |   |  |  |    |   |  |  \ \   /  __|
 |   | |   | ___ __|  ___ |  |   \ \ /   |
\____|\___/     _|   _|  _|___|   \_/   _____| 

 --- A GOPHER-LIKE INTERFACE FOR HIVE BLOCKCHAIN ---

#100DaysOfCode Day 3

BY: @christopherxc | CREATED: May 12, 2018, 5:07 a.m. | VOTES: 1 | PAYOUT: $0.00 | [ VOTE ]

[IMAGE: https://steemitimages.com/DQmPAxLpzqH2q1UBgEWDvF6XxpVvz24CZwQ4uLvTwXdYZTy/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 🤓

TAGS: [ #programming ] [ #onehundreddaysofcode ] [ #javascript ] [ #code ]

Replies

NO REPLIES FOUND.

[ BACK TO TRENDING ] [ BACK TO MENU ]
CMD>