JavaScriptmas interview type coding challenges
Tags: javascript, beginners, challenge, programming
Published: 2020-12-24 07:26:05

Cover image by <a href="https://pixabay.com/users/pexels-2286921/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1839876">Pexels</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1839876">Pixabay</a>
## Introduction

These are my solutions to a set of programming challenges by [scrimba](https://scrimba.com/) dubbed [JavaScriptmas](https://scrimba.com/learn/adventcalendar) which ran from December 01, 2020 to December 24, 2020. 

These challenges are mostly beginner programming problems. You might encounter one or two in a technical interview for an entry level job. If you are a beginner in JavaScript, it might help consolidate your JavaScript knowledge. I have documented my solutions here.  The same solutions can also be found on Scrimba by following the link below each challenge description. You are free to play with the code. 

If you are interested, I have also compiled these challenges in a GitHub repository which you can find at the link below.You are free to fork it under your own account and modify the solutions.


{% github nibble0101/javascriptmas %}


If you have a better solution or notice an inefficient or incorrect solution, feel free to open a pull request after reading the contribution guidelines or leave your solution in the comments section below. You never know someone might find it useful. I have written unit tests in [jest](https://jestjs.io/) which you can find at the GitHub repository.  


## Challenges

| No. | Challenge |
| --- | --- |
|[01](#candies)|[Candies](#candies)|
|[02](#deposit-profit)|[Deposit Profit](#deposit-profit)|
|[03](#chunky-monkey)|[Chunky Monkey](#chunky-monkey)|
|[04](#century-from-year)|[Century from year](#century-from-year)|
|[05](#reverse-string)|[Reverse string](#reverse-string)|
|[06](#sort-by-length)|[Sort by length](#sort-by-length)|
|[07](#count-vowel-consonants)|[Count vowel consonants](#count-vowel-consonants)|
|[08](#the-rolling-dice)|[The rolling dice](#the-rolling-dice)|
|[09](#sum-odd-fibonacci-numbers)|[Sum odd fibonacci numbers](#sum-odd-fibonacci-numbers)|
|[10](#adjacent-elements-product)|[Adjacent elements product](#adjacent-elements-product)|
|[11](#avoid-obstacles)|[Avoid obstacles](#avoid-obstacles)|
|[12](#valid-time)|[Valid time](#valid-time)|
|[13](#extract-each-kth)|[Extract each kth](#extract-each-kth)|
|[14](#array-maximal-adjacent-diff)|[Array maximal adjacent diff](#array-maximal-adjacent-diff)|
|[15](#javascript-carousel)|[JavaScript carousel](#javascript-carousel)|
|[16](#insert-dashes)|[Insert dashes](#insert-dashes)|
|[17](#different-symbols-naive)|[Different symbols naive](#different-symbols-naive)|
|[18](#array-previous-less)|[Array previous less](#array-previous-less)|
|[19](#alphabet-subsequence)|[Alphabet subsequence](#alphabet-subsequence)|
|[20](#domain-type)|[Domain type](#domain-type)|
|[21](#sum-of-2)|[Sum of 2](#sum-of-2)|
|[22](#extract-matrix-column)|[Extract matrix column](#extract-matrix-column)|
|[23](#tweet-input-component)|[Tweet Input Component](#tweet-input-component)|
|[24](#test-your-agility)|[Test your agility challenge](#test-your-agility)|

**********

**Candies** <a name = "candies"> </a>

`n` children have got `m` pieces of candy. They went to eat as much candy as they can, but each child must eat exactly the same amount of candy as any other child. Determine how many pieces of candy will be eaten by all the children together. Individual pieces of candy cannot be split.

**Example**
For `n = 3` and `m = 10`, the output should be `candies(n, m) = 9`. Each child will eat 3 pieces. So the answer is 9. 

```js
/**
* @params  integer
* @params  integer
* @returns integer
*/

function candies(children, candy) {
  
}
```
[Solution on Scrimba](https://scrimba.com/scrim/co5bd40fe98261ead515f8461)

{% details Solution 1 %}

```js
function candies(children, candy) {
  return Math.floor(candy / children) * children;
}
```

{% enddetails %}

{% details Solution 2 %}

```js
function candies(children, candy) {
   return candy - (candy % children);
}
```

{% enddetails %}

**********

**Deposit profit** <a name = "deposit-profit"> </a>

You have deposited a specific amount of dollars into your bank account. Each year your balance increases at the same growth rate. Find out how long it would take for your balance to pass a specific threshold with the assumption that you don't make any additional deposits. 

**Example**

For `deposit = 100`, `rate = 20` and `threshold = 170`, the output should be `depositProfit(deposit, rate, threshold) = 3`. Each year the amount of money on your account increases by 20%. It means that throughout the years your balance would be) 
- year 0: 100 
- year 1: 120 
- year 2: 144 
- year 3: 172.8

Thus, it will take 3 years for your balance to pass the threshold, which is the answer. 

```js
/**
*@params  number
*@params  number
*@params  number
*@returns number
*/
function depositProfit(deposit, rate, threshold) {

}
```

[Solution on Scrimba](https://scrimba.com/scrim/codb44b3dbdd4c20d4f3fe271)


{% details Solution %}

```js
function depositProfit(deposit, rate, threshold) {
  const years = Math.log(threshold / deposit) / Math.log(1 + rate / 100);
  return Number.isInteger(years) ? years + 1 : Math.ceil(years);
}
```

{% enddetails %}

**********

**Chunky Monkey**  <a name = "chunky-monkey"> </a>

Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array.

**Example**

- `chunkyMonkey(["a", "b", "c", "d"], 2)` should return `[["a", "b"], ["c", "d"]]` 
- `chunkyMonkey([0, 1, 2, 3, 4, 5], 4)` should return `[[0, 1, 2, 3], [4, 5]]`

```js
/**
*@params   any[]
*@params   integer
*@returns  Array<Array<any>>
*/
function chunkyMonkey(values, size) {
  
}
```

[Solution on Scrimba](https://scrimba.com/scrim/cob1f454eb9c89cc6d587323a)

{% details Solution %}

```js
function chunkyMonkey(values, size) {
  const chunkedArray = [];
  const arrayLength = values.length;
  for (let i = 0; i < arrayLength; i += size) {
    chunkedArray.push(values.slice(i, i + size));
  }
  return chunkedArray;
}
```

{% enddetails %}

**********

**Century from year** <a name = "century-from-year"> </a>

Given a year, return the century it is in. The first century spans from the year 1 up to and including the year 100. The second century from the year 101 up to and including the year 200.

Example
- For `year = 1905`, the output should be `centuryFromYear(year) = 20`.
- For `year = 1700`, the output should be `centuryFromYear(year) = 17`.
```js
/**
*@params  integer
*@returns integer
*/

function centuryFromYear(num) {
  
}
```

[Solution on Scrimba](https://scrimba.com/scrim/co5ae4a34b49636875e292ac5)

{% details Solution %}

```js
function centuryFromYear(num) {
  return num % 100 ? Math.ceil(num / 100) : num / 100;
}
```

{% enddetails %}

**********

**Reverse string** <a name = "reverse-string"> </a>

Reverse the provided string.You may need to turn the string into an array before you can reverse it. Your result must be a string.

**Examples**

- `reverseAString("hello")` returns `"olleh"`
- `reverseAString("Howdy")` returns `"ydwoH"`

```js
/**
*@params  string
*@returns string
*/

function reverseAString(str) {
 
}
```

[Solution on Scrimba](https://scrimba.com/scrim/co7b743899ba76ba3c97a1d88)

{% details Solution 1 %}

```js
function reverseAString(str) {
  return str.split('').reverse().join('');
}
```

{% enddetails %}

{% details Solution 2 %}

```js
function reverseAString(str) {
  let reversedString = ''; const { length } = str;
  for (let i = 0; i < length; i += 1) {
    reversedString = str[i] + reversedString;
  }
  return reversedString;
}
```

{% enddetails %}

**********

**Sort by length** <a name = "sort-by-length"></a>

Given an array of strings, sort them in the order of increasing lengths. If two strings have the same length, their relative order must be the same as in the initial array.

**Example**

```js
/**
*@params  [string]
*@returns [string]
*/
function sortByLength(strs) {
  
}
```

[Solution on Scrimba](https://scrimba.com/scrim/co164412a84c104d5b38e20ea)

{% collapsible Solution %}

```js
function sortByLength(strs) {
  return strs.sort((a, b) => a.length - b.length);
}
```

{% endcollapsible %}

**********

**Count vowel consonants** <a name = "count-vowel-consonants"> </a>

You are given a string `str` that consists of only lowercase English letters. If vowels ('a', 'e', 'i', 'o', 'u') are given a value of 1 and consonants are given a value of 2,return the sum of all of the letters in the input string.

**Example**
- For `str = "abcde"` the output should be `countVowelConsonant(str) = 8`.
```js
/**
*@params  string
*@returns integer
*/

function countVowelConsonant(str) {
 
}
```

[Solution on Scrimba](https://scrimba.com/scrim/co0c2498795dc311156004d6c)

{% spoiler Solution %}

```js
function countVowelConsonant(str) {
  return str.split('').reduce((count, char) => ('aeiou'.indexOf(char) === -1 ? count + 2 : count + 1), 0);
}
```

{% endspoiler %}

**********

**The rolling dice** <a name = "the-rolling-dice"> </a>

In this challenge a casino has asked you to make an online dice that works just like it would in real life. Using the dice face that represents ‘one’ which has been made for you, make the faces for ‘two’, ‘three’, ‘four’, ‘five’ and ‘six’. Now when the users clicks the dice on the screen the dice is expected to show one of the faces randomly.

**Note**
You can check the scrimba playground below for the HTML, CSS and JavaScript files.

[Solution on Scrimba](https://scrimba.com/scrim/co68940998971f4c8575eb894)

**********

**Sum odd fibonacci numbers** <a name = "sum-odd-fibonacci-numbers"></a>

Given a positive integer `num`, return the sum of all odd Fibonacci numbers that are less than or equal to `num`. The first two numbers in the Fibonacci sequence are 1 and 1. Every additional number in the sequence is the sum of the two previous numbers. The first six numbers of the Fibonacci sequence are 1, 1, 2, 3, 5, 8. For example `sumOddFibonacciNumbers(10)` should return 10 because all odd Fibonacci numbers less than or equal to 10 are 1, 1, 3, 5.

**Examples**
- `sumOddFibonacciNumbers(10)` should return `10`
- `sumOddFibonacciNumbers(1000)` should return `1785`
- `sumOddFibonacciNumbers(4000000)` should return `4613732`
```js
/**
*@params  integer
*@returns integer
*/
function sumOddFibonacciNumbers(num){

}
```
[Solution on Scrimba](https://scrimba.com/scrim/co5814e6a965456ca95998bfc)

{% collapsible Solution%}

```js
function sumOddFibonacciNumbers(num) {
  if (num < 2) return 2;
  const cache = [1, 1];
  let sumOfOddFibNums = 2;
  while (cache[0] + cache[1] <= num) {
    const nextFibNum = cache[0] + cache[1];
    if (nextFibNum % 2) {
      sumOfOddFibNums += nextFibNum;
    }
    cache[0] = cache[1];
    cache[1] = nextFibNum;
  }
  return sumOfOddFibNums;
}
```

{% endcollapsible %}

**********

**Adjacent elements product** <a name = "adjacent-elements-product"></a>

Given an array of integers, find the pair of adjacent elements that has the largest product and return the product.

**Examples**

- For `inputArray = [3, 6, -2, -5, 7, 3]` `adjacentElementsProduct(inputArray)` should return 21 because 7 and 3 produce the largest product

```js
/**
*@params  number[]
*@returns integer
*/

function adjacentElementsProduct(nums){

}
```

[Solution on Scrimba](https://scrimba.com/scrim/cof3544bea8def0c8771ec4a6)

{% spoiler Solution %}

```js
function adjacentElementsProduct(nums) {
  if (nums.length < 2) return nums[0];
  let product = nums[0] * nums[1];
  const lastIndex = nums.length - 1;

  for (let i = 1; i < lastIndex; i += 1) {
    if (nums[i] * nums[i + 1] > product) {
      product = nums[i] * nums[i + 1];
    }
  }
  return product;
}
```
{% endspoiler %}

**********

**Avoid obstacles** <a name = "avoid-obstacles"></a>

You are given an array of integers representing coordinates of obstacles situated on a straight line. Assume that you are jumping from the point with coordinate 0 to the right. You are allowed only to make jumps of the same length represented by some integer. Find the minimal length of the jump enough to avoid all obstacles. 

**Examples**

- For `inputArray = [5, 3, 6, 7, 9]` `avoidObstacles(inputArray)` should return 4.

```js
/**
*@params  number[]
*@returns integer
*/

function avoidObstacles(nums) {

}
```

[Solution on Scrimba](https://scrimba.com/scrim/coab74aedba0196192d071885)

{% spoiler Solution %}

```js
function avoidObstacles(nums) {
  if (!Array.isArray(nums) || !nums.length) {
    throw new Error('Requires integer array');
  }

  const largestObstacle = Math.max(...nums);

  /*
  OR:
  const largestObstacle = nums.reduce((prev, curr) => {
      return curr > prev ? curr : prev;
  });
  */

  for (let jump = 2; jump <= largestObstacle; jump += 1) {
    if (nums.every((obstacle) => obstacle % jump !== 0)) {
      return jump;
    }
  }
  return largestObstacle + 1;
}
```

{% endspoiler %}

**********

**Valid time** <a name = "valid-time"></a>

Check if the given string is a correct time representation of the 24-hour clock.

**Examples**

- For `time = "13:58"`, `validTime(time)` should return `true`.
- For `time = "25:51"`, `validTime(time)` should return `false`.
- For `time = "02:76"`, `validTime(time)` should return `false`.

```js
/**
*@params  string
*@returns boolean
*/

function validTime(str){

}
```

[Solution on Scrimba](https://scrimba.com/scrim/coa794f2f944d5754a3aa7465)

{% details Solution %}

```js
function validTime(str) {
  if (typeof str !== 'string' || !str.includes(':')) {
    return false;
  }
  let [hour, minutes] = str.trim().split(':');
  hour = hour.trim();
  minutes = minutes.trim();
  if (/\D/.test(hour) || /\D/.test(minutes)) {
    return false;
  }
  hour = parseInt(hour, 10);
  minutes = parseInt(minutes, 10);
  return hour >= 0 && hour < 24 && minutes >= 0 && minutes < 60;
}
```

{% enddetails %}

***********

**Extract each kth** <a name = "extract-each-kth"></a>

Given an array of integers, remove each k<sup>th</sup> element from it.

**Example**

- For `inputArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]` and `k = 3` the output of `extractEachKth(inputArray, k)`  should be `[1, 2, 4, 5, 7, 8, 10]`.

```js
/**
*@params  number[]
*@params  integer
*@returns number[]
*/

function extractEachKth(nums, index){

}
```

[Solution on Scrimba](https://scrimba.com/scrim/co5464586922a9fe70d269f8a)

{% details Solution %}

```js
function extractEachKth(nums, index) {
  return nums.filter((__, i) => (i + 1) % index !== 0);
}
```

{% enddetails %}

**********

**Array maximal adjacent difference** <a name = "array-maximal-adjacent-diff"></a>

Given an array of integers, find the maximal absolute difference between any two of its adjacent elements.

**Examples**

- For `inputArray = [2, 4, 1, 0]` `arrayMaximalAdjacentDifference(inputArray)` should return 3
- For `inputArray = [2, 9, 1, 0]` `arrayMaximalAdjacentDifference(inputArray)` should return 8

```js
/**
*@params number[]
*@returns number
*/

function arrayMaximalAdjacentDifference(nums){

}

```

[Solution on Scrimba](https://scrimba.com/scrim/coa0a435a89f39439abe12812)

{% details Solution %}

```js
function arrayMaximalAdjacentDifference(nums) {
  if (!Array.isArray(nums) || !nums.length) {
    throw new Error('Invalid argument');
  }

  if (nums.length < 2) return nums[0];

  let maxAbsoluteDiff = Math.abs(nums[0] - nums[1]);
  const lastIndex = nums.length - 1;

  for (let i = 1; i < lastIndex; i += 1) {
    const diff = Math.abs(nums[i] - nums[i + 1]);
    if (maxAbsoluteDiff < diff) {
      maxAbsoluteDiff = diff;
    }
  }

  return maxAbsoluteDiff;
}
```

{% enddetails %}

**********

**JavaScript carousel** <a name = "javascript-carousel"></a>

In this challenge, one is required to make carousel work using JavaScript. The HTML, CSS and JavaScript files can be found in the Scrimba playground by following the link below.

[Solution on Scrimba](https://scrimba.com/scrim/co8794fbebc1d96e938715eed)

{% details Solution %}

```js
const previousButton = document.querySelector('.previous');
const nextButton = document.querySelector('.next');
const allImages = document.querySelectorAll('img.card');
const gallery = document.querySelector('.gallery');
const imageCount = allImages.length;

let visibleImageId = 0;

function togglePreviousButtonBlur(action = 'INCREASE_OPACITY') {
  if (action === 'LOWER_OPACITY') {
    previousButton.style.opacity = 0.3;
    return;
  }
  previousButton.style.opacity = 1;
}

function toggleNextButtonBlur(action = 'INCREASE_OPACITY') {
  if (action === 'LOWER_OPACITY') {
    nextButton.style.opacity = 0.3;
    return;
  }
  nextButton.style.opacity = 1;
}

function translateGallery(visibleImageId) {
  const currentVisibleImage = document.querySelector('.current');

  currentVisibleImage.classList.remove('current');
  allImages[visibleImageId].classList.add('current');
  gallery.style.transform = `translateX(${visibleImageId * -220}px)`;
}

function previousButtonClickHandler() {
  if (visibleImageId === 0) return;

  translateGallery(--visibleImageId);

  if (visibleImageId === 0) {
    togglePreviousButtonBlur('LOWER_OPACITY');
    return;
  }
  togglePreviousButtonBlur();
  toggleNextButtonBlur();
}

function nextButtonClickHandler() {
  if (visibleImageId === imageCount - 1) return;

  translateGallery(++visibleImageId);

  if (visibleImageId === imageCount - 1) {
    toggleNextButtonBlur('LOWER_OPACITY');
    return;
  }
  toggleNextButtonBlur();
  togglePreviousButtonBlur();
}

previousButton.addEventListener('click', previousButtonClickHandler);
nextButton.addEventListener('click', nextButtonClickHandler);
```

{% enddetails %}

**********

**Insert dashes** <a name = "insert-dashes"></a>

Transform a given sentence into a new one with dashes between each two consecutive letters.

**Example**

- For `inputStr = "aba caba"`, `insertDashes(inputStr)` should return `"a-b-a c-a-b-a"`.

```js
/**
*@params  string
*@returns string
*/

function insertDashes(str){

}
```

[Solution on Scrimba](https://scrimba.com/scrim/co22f4aaebb054741883574c8)

{% spoiler Solution %}

```js
function insertDashes(str) {
  return str
    .split(' ')
    .map((word) => word.split('').join('-'))
    .join(' ');
}
```

{% endspoiler %}

**********

**Different symbols naive** <a name = "different-symbols-naive"></a>

Given a string, find the number of different characters in it.

**Example**

- For `inputStr = "cabca"`, `differentSymbolsNaive(inputStr)` should return 3 because there are three different characters a, b and c.

```js
/**
*@params  string
*@returns number
*/

function differentSymbolsNaive(str){

}
```

[Solution on Scrimba](https://scrimba.com/scrim/co67445b3ab196c95ef8e7966)

{% details Solution 1 %}

```js
function differentSymbolsNaive(str) {
  if (typeof str !== 'string') {
    throw new Error('Invalid input');
  }
  let uniqueChars = '';
  const { length } = str;
  for (let i = 0; i < length; i += 1) {
    if (!uniqueChars.includes(str[i])) {
      uniqueChars += str[i];
    }
  }
  return uniqueChars.length;
}

```

{% enddetails %}

{% details Solution 2 %}

```js
function differentSymbolsNaive(str) {
  if (typeof str !== 'string') {
    throw new Error('Invalid input');
  }
  return new Set(str).size;
}
```

{% enddetails %}

{% details Solution 3 %}

```js
function differentSymbolsNaive(str) {
  if (typeof str !== 'string') {
    throw new Error('Invalid input');
  }
  const uniqueChars = {};
  return str.split('').reduce((charCount, char) => {
    if (uniqueChars[char]) {
      return charCount;
    }
    uniqueChars[char] = char;
    return charCount + 1;
  }, 0);
}
```

{% enddetails %}

**********

**Array previous less** <a name = "array-previous-less"></a>

Given an array of integers, for each position `i`, search among the previous positions for the last (from the left) position that contains a smaller value. Store that value at position `i` in the answer. If no such value can be found, store -1 instead.

**Examples**

- For `inputArray = [3, 5, 2, 4, 5]`, `arrayPreviousLess(inputArray)` should return `[-1, 3, -1, 2, 4]`.

```js
/**
*@params  number[]
*@returns number[]
*/

function arrayPreviousLess(nums) {

}
```

[Solution on Scrimba](https://scrimba.com/scrim/cof4049ad9ec1f080cf5a8383)

{% details Solution 1 %}

```js
function arrayPreviousLess(nums) {
  if (!Array.isArray(nums)) {
    throw new Error('Invalid input');
  }
  const { length } = nums;
  const arrayClone = [...nums];

  // eslint-disable-next-line no-restricted-syntax
  outerLoop: for (let i = 0; i < length; i += 1) {
    if (typeof nums[i] !== 'number') {
      throw new Error('Invalid input');
    }
    for (let j = i - 1; j >= 0; j -= 1) {
      if (nums[i] > nums[j]) {
        arrayClone[i] = nums[j];
        // eslint-disable-next-line no-continue
        continue outerLoop;
      }
    }
    arrayClone[i] = -1;
  }
  return arrayClone;
}

```

{% enddetails %}

{% details Solution 2 %}

```js
function arrayPreviousLess(nums) {
  if (!Array.isArray(nums)) {
    throw new Error('Invalid input');
  }
  const arrayClone = [...nums];
  nums.forEach((element, index) => {
    if (typeof element !== 'number') {
      throw new Error('Invalid input');
    }
    for (let i = index - 1; i >= 0; i -= 1) {
      if (element > nums[i]) {
        arrayClone[index] = nums[i];
        return;
      }
    }
    arrayClone[index] = -1;
  });
  return arrayClone;
}

```

{% enddetails %}

**********

**Alphabet subsequence** <a name = "alphabet-subsequence"></a>

Check whether the given string is a subsequence of the plaintext alphabet

**Examples**

- For `inputStr = "effg"`, `alphabetSubsequence(inputStr)` should return `false`
- For `inputStr = "cdce"`, `alphabetSubsequence(inputStr)` should return `false`
- For `inputStr = "ace"`, `alphabetSubsequence(inputStr)` should return `true`
- For `inputStr = "bxz"`, `alphabetSubsequence(inputStr)` should return `true`

```js
/**
*@param   string
*@returns boolean
*/

function alphabetSubsequence(str){

}
```

[Solution on Scrimba](https://scrimba.com/scrim/co40040f498a6e221867f7378)

{% spoiler Solution %}

```js
function alphabetSubsequence(str) {
  if (typeof str !== 'string' || !str.length) {
    throw new Error('Invalid input');
  }
  const lowerCaseStr = str.toLowerCase();
  const lastIndex = str.length - 1;
  for (let i = 0; i < lastIndex; i += 1) {
    const thisCharCode = lowerCaseStr.charCodeAt(i);
    const nextCharCode = lowerCaseStr.charCodeAt(i + 1);
    if (nextCharCode <= thisCharCode) {
      return false;
    }
    if (thisCharCode < 97 || thisCharCode > 122) {
      return false;
    }
  }
  const lastCharCode = lowerCaseStr[lastIndex];
  return !(lastCharCode < 97 || lastCharCode > 122);
}
```

{% endspoiler %}

***********

**Domain type** <a name = "domain-type"></a>

GoDaddy makes a lot of different top-level domains available to its customers. A top-level domain is one that goes directly after the last dot (`.`) in the domain name, for example `.com` in `example.com`. To help the users choose from available domains, GoDaddy is introducing a new feature that shows the type of the chosen top-level domain. You have to implement this feature. To begin with, you want to write a function that labels the domains as "commercial", "organization", "network" or "information" for .com, .org, .net or .info respectively. For the given list of domains, return the list of their labels.

**Example**

- For `domains = ["en.wiki.org", "codefights.com", "happy.net", "code.info"]`, `domainType(domains)` should return `["organization", "commercial", "network", "information"]`.

```js
/**
*@params   Array<string>
*@returns  Array<string>
*/

function domainType(domains){

}
```

[Solution on Scrimba](https://scrimba.com/scrim/co3204f05aa061687ff0832b1)

{% details Solution %}

```js
function domainType(domains) {
  return domains.map((domain) => {
    const domainNameComponents = domain.split('.');
    const topLevelDomain = domainNameComponents[domainNameComponents.length - 1];
    switch (topLevelDomain) {
      case 'com':
        return 'commercial';
      case 'org':
        return 'organization';
      case 'net':
        return 'network';
      case 'info':
        return 'information';
      default:
    }
  });
}
```

{% enddetails %}

**********

**Sum of 2** <a name = "sum-of-2"></a>

You have two integer arrays `a` and `b`, and an integer target value `v`. Determine whether there is a pair of numbers, one number taken from `a` and another from `b` that can be added together to get a sum of `v`. Return `true` if such a pair exists, otherwise return `false`.

**Examples**

- For `a = [1, 2, 3]`, `b = [10, 20, 30, 40]` and `v = 42`, `sumOfTwo(a, b, v)` should return `true`.

```js
/**
*@params  number[]
*@params  number[]
*@params  number
*@returns boolean
*/

function sumOfTwo(nums1, nums2, value){

}
```

[Solution on Scrimba](https://scrimba.com/scrim/co921443ea807f3f09cd8ec09)

{% details Solution %}

```js
function sumOfTwo(nums1, nums2, value) {
  for (let i = 0; i < nums1.length; i += 1) {
    for (let j = 0; j < nums2.length; j += 1) {
      if (nums1[i] + nums2[j] === value) {
        return true;
      }
    }
  }
  return false;
}
```

{% enddetails %}

**********

**Extract matrix column** <a name = "extract-matrix-column"></a>

Given a rectangular matrix and an integer column, return an array containing the elements of the column<sup>th</sup> column of the given matrix. The leftmost column is the 0<sup>th</sup> column.

**Example**

- For `inputMatrix = [[1, 1, 1, 2], [0, 5, 0, 4], [2, 1, 3, 6]]` and `column = 2`, `extractMatrixColumn(inputMatrix, column)` should return `[1, 0, 3]`.

```js
/**
*@params  Array<Array<number>>
*@returns number[]
*/
function extractMatrixColumn(matrix, column) {
 
}
```

[Solution on Scrimba](https://scrimba.com/scrim/co2d841138d75becae9d526eb)

{% details Solution %}

```js
function extractMatrixColumn(matrix, column) {
  return matrix.map((row) => row[column]);
}
```

{% enddetails %}

**********

**Tweet Input Component** <a name = "tweet-input-component"></a>

In this challenge, you are expected to make a Social Media Character Counter! You need to display the available characters LEFT. Using the Keydown event should help you here. When the characters reach 20 and below, we want them to turn red. So we will use Javascript to add that styling to it. If the characters drop below 0, we want the button to be disabled BUT if there are only 0 characters left, we should still be able to tweet.

You can find the HTML, CSS and JavaScript files at the link below.

[Solution on Scrimba](https://scrimba.com/scrim/co3534c9ca0dc280a6a4c12b1)

**********

**Test your agility challenge** <a name = "test-your-agility"></a>

Make a counter that increments every 75 milliseconds in the `spin()` function and display whether the player wins or losses in the `stop()` function.

**Note**
Check the HTML, CSS and JavaScript files on Scrimba by following the link below.

[Solution on Scrimba](https://scrimba.com/scrim/co1da4080bdb68dfb1ae74e0b)

**********

You can also fork the GitHub repository for the challenges in the link below.
{% github nibble0101/javascriptmas no-readme %}

If you found these challenges useful, feel free to [tweet](https://twitter.com/) or share them on any other platform. Others might find them useful too.