Join the conversation

Sign in to join this conversation, and others like it, in the communities you care about.

Scotch

Top shelf web development community

Scotch / Bar Talk

Code Challenge #11: JavaScript Functional Programming

Code Challenge #11: JavaScript Functional Programming

June 12, 2018 · 8:30pm(Edited 1 week ago)
https://scotch.io/bar-talk/code-challenge-11-javascript-functional-programming


This week on the code challenge, we'll be re-visiting the basics of JavaScript with Arrays.
This challenge is quite unique such that we will be using some really useful built-in array methods to manipulate the provided arrays. Three arrays are provided and each comes with 3 problem parts to be solved...
Code Challenge #11: JavaScript Functional Programming
http://scotch.io/bar-talk/code-challenge-11-javascript-functional-programming

June 12, 2018 · 8:33pm

Let's go back to the basics!

like-fill
0
reply

Nice!

like-fill
0
reply

June 13, 2018 · 3:16am

Very impressive

like-fill
1
reply

June 14, 2018 · 4:27pm

by far `.sort` is the hardest function to implement by hand

like-fill
0
reply

June 18, 2018 · 1:05am

#scotchchallenge @scotch_io

Code Challenge #11: JavaScript Functional Programming

https://codepen.io/leandrw/pen/xzLYwX

like-fill
2
reply

June 18, 2018 · 3:54pm

#scotchchallenge @scotch_io

Code Challenge #11: JavaScript Functional Programming https://codepen.io/Adroit11/pen/MXOxVv

like-fill
2
reply

Nice!

like-fill
0
reply

June 24, 2018 · 10:25am

I tried it too!

like-fill
0
reply

To find the total age of the users you don't even need .map() :D

like-fill
0
reply

You can use .reduce()'s second argument, the initial value!

like-fill
0
reply
const ageSum = [(p, c) => p + c.age, 0];

console.log(texasss.reduce(...ageSum)) // 202

like-fill
0
reply

And using that, especially the last challenge is really simple in just one line:

like-fill
0
reply
[...texasss, ...newieyork, ...vegzas].reduce(...ageSum) // 529

like-fill
0
reply

I didn't want to use CodPen btw, I used repl.it instead: https://repl.it/repls/BluevioletUnderstatedCharacter

like-fill
0
reply
Your message here...

*bold*_italic_`code````codeblock```