My simplistic entries for Scrimba's 2020 #JavaScriptmas advent calendar
Tags: javascript, development, scrimba, coding
Published: 2020-12-31 17:07:23

---
title: My simplistic entries for Scrimba's 2020 #JavaScriptmas advent calendar
published: true
description: A list of my entries for every entry from Scrimba's 2020 #JavaScriptmas advent calendar JavaScript challenges
tags: javascript, development, javascript, scrimba, coding
cover_image: https://i.imgur.com/MGW2rNx.png
---

##### [↓ Skip to the challenges ↓](#toc)

<small>…</small>

Scrimba filled this month with plenty of new JavaScript challenges for us to complete with their <a href="https://twitter.com/search?q=(%23JavaScriptmas)%20(%40scrimba)" target="_blank">#JavaScriptmas</a> tradition, leading up to Christmas day. Here are my highly simplistic solutions to each challenge, using only one-liner JavaScript functions for all non-project-style challenges. For the project-style challenges (Days 8, 15, 23, and an extra bonus challenge Scrimba included between days 23 and 24), I embedded my full solutions using CodePen so you can poke around to see how I solved each one.

Front-end development is my full-time career, but as work tends to be a lot of the same, it's nice to mix it up now and again and tackle some challenges that not only spice up the routine development but also challenge you to learn new methods and techniques. My personal favorite challenges were the [Sum Odd Fibonacci Numbers](#challenge-9) challenge in which I "hijacked" the temporary array being created by the third parameter of the `Array.prototype.map()` function, and the [Max Consecutive Sum](#challenge-24) challenge which expanded my knowledge of the `Array.prototype.fill()` function. For some CSS fun, check out the CSS tab of [Challenge 8](#challenge-8) to see how I created my different dice faces.

Without any further ado — enjoy! ☕️🎄🎁<a name="toc"></a>

## Table Of Contents
  * [🍬 **Challenge 1:** Candies](#challenge-1)
  * [⭐️ **Challenge 2:** Deposit Profit](#challenge-2)
  * [🧚 **Challenge 3:** Chunky Monkey](#challenge-3)
  * [🎄 **Challenge 4:** Century From Year](#challenge-4)
  * [🐑 **Challenge 5:** Reverse a String ](#challenge-5)
  * [🤶 **Challenge 6:** Sort by Length](#challenge-6)
  * [🦌 **Challenge 7:** Count Vowel Consonant](#challenge-7)
  * [🔔 **Challenge 8:** The Rolling Dice](#challenge-8)
  * [🎺 **Challenge 9:** Sum Odd Fibonacci Numbers](#challenge-9)
  * [💂‍♀️ **Challenge 10:** Adjacent Elements Product](#challenge-10)
  * [🎁 **Challenge 11:** Avoid Obstacles](#challenge-11)
  * [❄️ **Challenge 12:** Valid Time](#challenge-12)
  * [🤴 **Challenge 13:** Extract Each Kth](#challenge-13)
  * [🧸 **Challenge 14:** Maximal Adjacent Difference](#challenge-14)
  * [🕊 **Challenge 15:** Carousel](#challenge-15)
  * [🧦 **Challenge 16:** Insert Dashes](#challenge-16)
  * [👑 **Challenge 17:** Different Symbols Naive](#challenge-17)
  * [🎅🏻 **Challenge 18:** Array Previous Less](#challenge-18)
  * [🐫 **Challenge 19:** Alphabet Subsequence](#challenge-19)
  * [✨ **Challenge 20:** Domain Type](#challenge-20)
  * [🦃 **Challenge 21:** Sum of Two](#challenge-21)
  * [👼 **Challenge 22:** Extract Matrix Column](#challenge-22)
  * [🌠 **Challenge 23:** Social Media Input](#challenge-23)
  * [💯 **Challenge BONUS:** Test Your Agility](#challenge-bonus)
  * [☃️ **Challenge 24:** Max Consecutive Sum](#challenge-24)<a name="challenge-1"></a>




### 🍬 &nbsp; **Challenge 1:** Candies

```js
const candies = (children, candy) => Math.floor(candy / children) * children;
candies(3, 10); // 9
```
<small>[Take a swing at Challenge 1](https://scrimba.com/learn/adventcalendar/-javascript-challenge-candies-introduction-cLkqvpcQ)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-2"></a></small></strong>




### ⭐️ &nbsp; **Challenge 2:** Deposit Profit

```js
const depositProfit = (deposit, rate, threshold) => Math.ceil(Math.log(threshold / deposit) / Math.log(1 + (rate / 100)));
depositProfit(100, 20, 170); // 3
```
<small>[Take a swing at Challenge 2](https://scrimba.com/learn/adventcalendar/-javascript-challenge-deposit-profit-introduction-cPk7yptk)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-3"></a></small></strong>




### 🧚 &nbsp; **Challenge 3:** Chunky Monkey

```js
const chunkyMonkey = (values, size) => values.length <= size ? [values] : [values.slice(0, size), ...chunkyMonkey(values.slice(size), size)];
chunkyMonkey(["a", "b", "c", "d"], 2); // [["a", "b"], ["c", "d"]]
```
<small>[Take a swing at Challenge 3](https://scrimba.com/learn/adventcalendar/-javascript-challenge-chunky-monkey-introduction-cLkqvyAR)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-4"></a></small></strong>




### 🎄 &nbsp; **Challenge 4:** Century From Year

```js
const centuryFromYear = num => Math.ceil(num/100);
centuryFromYear(1905); // 20
centuryFromYear(1700); // 17
```
<small>[Take a swing at Challenge 4](https://scrimba.com/learn/adventcalendar/javascript-challenge-century-from-year-introduction-cNDr7NUB)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-5"></a></small></strong>




### 🐑 &nbsp; **Challenge 5:** Reverse a String 

```js
const reverseAString = str => str.split('').reverse().join('');
reverseAString('hello'); // "olleh"
```
<small>[Take a swing at Challenge 5](https://scrimba.com/learn/adventcalendar/-javascript-challenge-reverse-a-string-introduction-c9rME3fv)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-6"></a></small></strong>




### 🤶 &nbsp; **Challenge 6:** Sort by Length

```js
const sortByLength = strs => strs.sort((a,b) => a.length - b.length, 0);
sortByLength(["abc", "", "aaa", "a", "zz"]); // ["", "a", "zz", "abc", "aaa"]
```
<small>[Take a swing at Challenge 6](https://scrimba.com/learn/adventcalendar/-javascript-challenge-sort-by-length-introduction-cyw87yuK)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-7"></a></small></strong>




### 🦌 &nbsp; **Challenge 7:** Count Vowel Consonant

```js
const countVowelConsonant = str => str.split('').reduce((a,b) => a + (/[aAeEiIoOuU]/.test(b) ? 1 : 2), 0);
countVowelConsonant('abcde'); // 8
```
<small>[Take a swing at Challenge 7](https://scrimba.com/learn/adventcalendar/javascript-challenge-count-vowel-consonant-introduction-coa5e49d4b957084837f19509)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-8"></a></small></strong>




### 🔔 &nbsp; **Challenge 8:** The Rolling Dice

{% codepen https://codepen.io/twhite96/pen/qBaxjpz default-tab=js,result %}
<small>[Take a swing at Challenge 8](https://scrimba.com/learn/adventcalendar/-javascriptmas-challenge-the-rolling-dice-introduction-c36yeWh7)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-9"></a></small></strong>




### 🎺 &nbsp; **Challenge 9:** Sum Odd Fibonacci Numbers

```js
const sumOddFibonacciNumbers = num => [0,1,1,...Array(num-3).fill()].map((e,i,a) => a[i-2] ? ((a[i] = a[i-2] + a[i-1]) || a[i-2] + a[i-1]) : e).filter(e => e % 2 && e <= num).reduce((a,b) => a + b, 0);
sumOddFibonacciNumbers(10); // 10
sumOddFibonacciNumbers(1000); // 1785
```
<small>[Take a swing at Challenge 9](https://scrimba.com/learn/adventcalendar/-javascript-challenge-sum-odd-fibonacci-numbers-introduction-cmpWaRcW)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-10"></a></small></strong>




### 💂‍♀️ &nbsp; **Challenge 10:** Adjacent Elements Product

```js
const adjacentElementsProduct = nums => Math.max(...nums.map((e,i,a) => a[i-1] ? e * a[i-1] : "").filter(e => e)) || undefined;
adjacentElementsProduct([3, 6, -2, -5, 7, 3]); // 21
```
<small>[Take a swing at Challenge 10](https://scrimba.com/learn/adventcalendar/-javascript-challenge-adjacent-elements-product-introduction-c8q4NRCE)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-11"></a></small></strong>




### 🎁 &nbsp; **Challenge 11:** Avoid Obstacles

```js
const avoidObstacles = nums => Array(Math.max(...nums)).fill().map((e, i) => i + 1).filter(e => !nums.includes(e)).find(e => nums.every(f => f % e !== 0));
avoidObstacles([5, 3, 6, 7, 9]); // 4
```
<small>[Take a swing at Challenge 11](https://scrimba.com/learn/adventcalendar/-javascript-challenge-avoid-obstacles-introduction-crGrJPTm)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-12"></a></small></strong>




### ❄️ &nbsp; **Challenge 12:** Valid Time

```js
const validTime = str => str.includes(":") && str.split(":").length === 2 && str.split(":").every(e => !isNaN(e)) && Array(24).fill().map((_,i) => i).includes(parseInt(str.split(":")[0])) && Array(60).fill().map((_,i) => i).includes(parseInt(str.split(":")[1]));
validTime('13:58'); // true
validTime('25:51'); // false
validTime('02:76'); // false
```
<small>[Take a swing at Challenge 12](https://scrimba.com/learn/adventcalendar/-javascript-challenge-valid-time-introduction-cLkq4bSQ)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-13"></a></small></strong>




### 🤴 &nbsp; **Challenge 13:** Extract Each Kth

```js
const extractEachKth = (nums, index) => nums.filter(e => e % index);
extractEachKth([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3); // [1, 2, 4, 5, 7, 8, 10]
```
<small>[Take a swing at Challenge 13](https://scrimba.com/learn/adventcalendar/-javascript-challenge-extract-each-kth-introduction-ce96GEHP)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-14"></a></small></strong>




### 🧸 &nbsp; **Challenge 14:** Maximal Adjacent Difference

```js
const arrayMaximalAdjacentDifference = nums => Math.max(...nums.map((e,i,a) => a[i-1] - e).filter(e => e).map(e => Math.abs(e))) || undefined;
arrayMaximalAdjacentDifference([2, 4, 1, 0]); // 3
arrayMaximalAdjacentDifference([2, 9, 1, 0]); // 8
```
<small>[Take a swing at Challenge 14](https://scrimba.com/learn/adventcalendar/-javascript-challenge-maximal-adjacent-difference-introduction-ckRE4Kt9)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-15"></a></small></strong>




### 🕊 &nbsp; **Challenge 15:** Carousel

{% codepen https://codepen.io/twhite96/pen/XWjZgBO default-tab=js,result %}
<small>[Take a swing at Challenge 15](https://scrimba.com/learn/adventcalendar/-javascript-challenge-carousel-c9r874s3)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-16"></a></small></strong>




### 🧦 &nbsp; **Challenge 16:** Insert Dashes

```js
const insertDashes = arr => arr.split(" ").map(e => [...e].join("-")).join(" ");
insertDashes("aba caba"); // "a-b-a c-a-b-a"
```
<small>[Take a swing at Challenge 16](https://scrimba.com/learn/adventcalendar/-javascript-challenge-insert-dashes-introduction-co2914310ba38bcaab285ccfa)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-17"></a></small></strong>




### 👑 &nbsp; **Challenge 17:** Different Symbols Naive

```js
const differentSymbolsNaive = str => [...new Set(str)].length;
differentSymbolsNaive('cabca'); // 3
```
<small>[Take a swing at Challenge 17](https://scrimba.com/learn/adventcalendar/-javascript-challenge-different-symbols-naive-introduction-cocf74b85b168559bf4e75a1a)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-18"></a></small></strong>




### 🎅🏻 &nbsp; **Challenge 18:** Array Previous Less

```js
const arrayPreviousLess = nums => nums.map((e,i,a) => a[i-1] < e ? a[i-1] : -1);
arrayPreviousLess([3, 5, 2, 4, 5]); // [-1, 3, -1, 2, 4]
```
<small>[Take a swing at Challenge 18](https://scrimba.com/learn/adventcalendar/-javascript-challenge-array-previous-less-introduction-co8cd43f5a1ebd5c407f1b3f8)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-19"></a></small></strong>




### 🐫 &nbsp; **Challenge 19:** Alphabet Subsequence

```js
const alphabetSubsequence = str => str === [...new Set(str)].sort().join('');
alphabetSubsequence('effg'); // false
alphabetSubsequence('cdce'); // false
alphabetSubsequence('ace');  // true
```
<small>[Take a swing at Challenge 19](https://scrimba.com/learn/adventcalendar/-javascript-challenge-alphabet-subsequence-introduction-czbJ4Jt9)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-20"></a></small></strong>




### ✨ &nbsp; **Challenge 20:** Domain Type

```js
const domainType = (domains, domainTypes = { com: "commercial", net: "network", org: "organization", info: "information" }) => domains.map(e => e.split('.')[e.split('.').length-1]).map(e => domainTypes[e]);
domainType(["en.wiki.org", "codefights.com", "happy.net", "code.info"]); // ["organization", "commercial", "network", "information"]
```
<small>[Take a swing at Challenge 20](https://scrimba.com/learn/adventcalendar/-javascript-challenge-domain-type-introduction-czbwRaH8)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-21"></a></small></strong>




### 🦃 &nbsp; **Challenge 21:** Sum of Two

```js
const sumOfTwo = (nums1, nums2, value) => nums1.map(e => nums2.map(f => e + f)).flat().some(e => e === value);
sumOfTwo([1, 2, 3], [10, 20, 30, 40], 42); // true
```
<small>[Take a swing at Challenge 21](https://scrimba.com/learn/adventcalendar/-javascript-challenge-sum-of-two-introduction-cE9B9rfE)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-22"></a></small></strong>




### 👼 &nbsp; **Challenge 22:** Extract Matrix Column

```js
const extractMatrixColumn = (matrix, column) => matrix.map(e => e[column]);
extractMatrixColumn([[1, 1, 1, 2], [0, 5, 0, 4], [2, 1, 3, 6]], 2); // [1, 0, 3]
```
<small>[Take a swing at Challenge 22](https://scrimba.com/learn/adventcalendar/-javascript-challenge-extract-matrix-column-introduction-co9a8445aab096f48e7e5ecf5)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-23"></a></small></strong>




### 🌠 &nbsp; **Challenge 23:** Social Media Input

{% codepen https://codepen.io/twhite96/pen/bGwLRJa default-tab=js,result %}
<small>[Take a swing at Challenge 23](https://scrimba.com/learn/adventcalendar/-javascript-challenge-social-media-input-crqLDVud)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-bonus"></a></small></strong>




### 💯 &nbsp; **Challenge BONUS:** Test Your Agility

{% codepen https://codepen.io/twhite96/pen/OJRQjJO default-tab=js,result %}
<small>[Take a swing at this Challenge BONUS](https://scrimba.com/learn/adventcalendar/test-your-agility-coc854c8d9bf01f02843f1b5c)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)<a name="challenge-24"></a></small></strong>




### ☃️ &nbsp; **Challenge 24:** Max Consecutive Sum

```js
const arrayMaxConsecutiveSum = (nums, elementCount) => Array(nums.length - elementCount + 1).fill().map((_,i) => nums.slice(i, i + elementCount)).map(e => e.reduce((a,b) => a + b, 0)).reduce((a,b) => a > b ? a : b);
arrayMaxConsecutiveSum([2, 3, 5, 1, 6], 2); // 8
```
<small>[Take a swing at Challenge 24](https://scrimba.com/learn/adventcalendar/-javascript-challenge-max-consecutive-sum-solution-cp38Mrt8)</small> &nbsp;&nbsp; // &nbsp;&nbsp; <strong><small>[↑ Back to the Table of Contents ↑](#toc)</small></strong>