Very easy

Going through edabit stage by stage to see my power level.

Uh... never mind, the very easy one's are a little...easy. Let's move on to...

Easy

Bitwise Operations by Helen Yu
Details

A decimal number can be represented as a sequence of bits. To illustrate:

6 = 00000110
23 = 00010111

From the bitwise representation of numbers, we can calculate the bitwise AND, bitwise OR and bitwise XOR. Using the example above:

bitwiseAND(6, 23) ➞ 00000110

bitwiseOR(6, 23) ➞ 00010111

bitwiseXOR(6, 23) ➞ 00010001

Write three functions to calculate the bitwise AND, bitwise OR and bitwise XOR of two numbers.

Examples

bitwiseAND(7, 12) ➞ 4

bitwiseOR(7, 12) ➞ 15

bitwiseXOR(7, 12) ➞ 11

Notes

JavaScript has a useful function: toString(2), where you can see the binary representation of a decimal number.

bitwiseAND bitwiseOR bitwiseXOR // Bonus toString toNum
Tuck in Array by Jeroen Ndh
Details

Create a function that takes two arrays and insert the second array in the middle of the first array.

Examples

tuckIn([1, 10], [2, 3, 4, 5, 6, 7, 8, 9]) ➞ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

tuckIn([15,150], [45, 75, 35]) ➞ [15, 45, 75, 35, 150]

tuckIn([[1, 2], [5, 6]], [[3, 4]]) ➞ [[1, 2], [3, 4], [5, 6]]

Notes

  • The first array always has two elements.
  • Use the spread syntax to solve this challenge.
tuckIn
Drink Sorting by meesie1
Details

You will be given an array of drinks, with each drink being an object with two properties: name and price. Create a function that has the drinks array as an argument and return the drinks objects sorted by price in ascending order.

Assume that the following array of drink objects needs to be sorted:

drinks = [
  {name: "lemonade", price: 50},
  {name: "lime", price: 10}
]

The output of the sorted drinks object will be:

Examples

sortDrinkByPrice(drinks) ➞ [{name: "lime", price: 10}, {name: "lemonade", price: 50}]

Notes

N/A

let drinks = [

]
sortDrinkByPrice
What's Hiding Amongst the Crowd? by Matt
Details

A word is on the loose and now has tried to hide amongst a crowd of tall letters! Help write a function to detect what the word is, knowing the following rules:

  • The wanted word is in lowercase.
  • The crowd of letters is all in uppercase.
  • Note that the word will be spread out amongst the random letters, but their letters remain in the same order.

Examples

detectWord("UcUNFYGaFYFYGtNUH") ➞ "cat"

detectWord("bEEFGBuFBRrHgUHlNFYaYr") ➞ "burglar"

detectWord("YFemHUFBbezFBYzFBYLleGBYEFGBMENTment") ➞ "embezzlement"

Notes

N/A

hideWord detectWord
Older Than Me by er0s
Details

Create a method in the Person class which returns how another person's age compares. Given the instances p1, p2 and p3, which will be initialised with the attributes name and age, return a sentence in the following format:

{other person name} is {older than / younger than / the same age as} me.

Examples

p1 = Person("Samuel", 24)
p2 = Person("Joel", 36)
p3 = Person("Lily", 24)
p1.compareAge(p2) ➞ "Joel is older than me."

p2.compareAge(p1) ➞ "Samuel is younger than me."

p1.compareAge(p3) ➞ "Lily is the same age as me."

Notes

  • Check out the Resources tab for some helpful tutorials on JavaScript classes!
  • If you're really stuck, check out the Solutions tab for answers.
let [p1,p2] = [

]
p1.compareAge
Largest Swap by Helen Yu
Details

Write a function that takes a two-digit number and determines if it's the largest of two possible digit swaps.

To illustrate:

largestSwap(27) ➞ false

largestSwap(43) ➞ true

If 27 is our input, we should return false because swapping the digits gives us 72, and 72 > 27. On the other hand, swapping 43 gives us 34, and 43 > 34.

Examples

largestSwap(14) ➞ false

largestSwap(53) ➞ true

largestSwap(99) ➞ true

Notes

Numbers with two identical digits (third example) should yield true (you can't do better).

largestSwap

Okay, I'm getting bored. On to...

Medium

How Much is True? by ente
Details

Create a function which returns the number of true values there are in an array.

Examples

countTrue([true, false, false, true, false]) ➞ 2

countTrue([false, false, false, false]) ➞ 0

countTrue([]) ➞ 0

Notes

  • Return 0 if given an empty array.
  • All array items are of the type bool (true or false).
const arr = [

]
countTrue
Find Number of Digits in Number by jordan sumitomo
Details

Create a function that will return an integer number corresponding to the amount of digits in the given integer num.

Examples

num_of_digits(1000) ➞ 4

num_of_digits(12) ➞ 2

num_of_digits(1305981031) ➞ 10

num_of_digits(0) ➞ 1

Notes

Try to solve this challenge without using strings!

num_of_digits
Perimeters with a Catch by BijogFc24
Details

Write a function that takes a number and returns the perimeter of either a circle or a square. The input will be in the form (letter l, number num) where the letter will be either "s" for square, or "c" for circle, and the number will be the side of the square or the radius of the circle.

Use the following formulas:

Perimeter of a square: 4 * side.
Perimeter of a circle: 6.28 * radius.

The catch is you can only use arithmetic or comparison operators, which means:

  • No if... else statements.
  • No objects.
  • No arrays.
  • No formatting methods, etc.

The goal is to write a short, branch-free piece of code.

Examples

perimeter("s", 7) ➞ 28

perimeter("c", 4) ➞ 25.12

perimeter("c", 9) ➞ 56.52

Notes

No rounding is needed.

perimeter perimeter
Which Generation Are You? by Jeroen Ndh
Details

Try finding your ancestors and offspring with code.

Create a function that takes a number x and a character y ("m" for male, "f" for female), and returns the name of an ancestor (m/f) or descendant (m/f).

  • If the number is negative, return the related ancestor.
  • If positive, return the related descendant.
  • You are generation 0. In the case of 0 (male or female), return "me!".

Examples

generation(2, "f") ➞ "granddaughter"

generation(-3, "m") ➞ "great grandfather"

generation(1, "f") ➞ "daughter"

Notes

Check the Resources tab for helpful hints.

GenerationMaleFemale
-3great grandfathergreat grandmother
-2grandfathergrandmother
-1fathermother
0me!me!
1sondaughter
2grandsongranddaughter
3great grandsongreat granddaughter
generation
A Redundant Function by Helen Yu
Details

Write a function redundant that takes in a string str and returns a function that returns str.

Examples

const f1 = redundant("apple")
f1() ➞ "apple"

const f2 = redundant("pear")
f2() ➞ "pear"

const f3 = redundant("")
f3() ➞ ""

Notes

Your function should return a function, not a string.

const fn = redundant;
fn();
Tile Teamwork Tactics by Matt
Details

In a board game, a piece may advance 1-6 tiles forward depending on the number rolled on a six-sided die. If you advance your piece onto the same tile as another player's piece, both of you earn a bonus.

Can you reach your friend's tile number in the next roll? Create a function that takes your position a and your friend's position b and returns a boolean representation of whether it's possible to earn a bonus on any die roll.

Examples

possibleBonus(3, 7) ➞ true

possibleBonus(1, 9) ➞ false

possibleBonus(5, 3) ➞ false

Notes

  • You cannot move backward (which is why example #3 doesn't work).
  • If you are already on the same tile, return false, as you would be advancing away.
  • Expect only positive integer inputs.
possibleBonus
Find the nth Tetrahedral Number by Matt
Details

A tetrahedron is a pyramid with a triangular base and three sides. A tetrahedral number is a number of items within a tetrahedron.

Create a function that takes an integer n and returns the nth tetrahedral number.

Alternative Text

Examples

tetra(2) ➞ 4

tetra(5) ➞ 35

tetra(6) ➞ 56

Notes

There is a formula for the nth tetrahedral number.

tetra betterTetra

Hard

Ooh.

Sum of Missing Numbers by Mubashir Hassan
Details

Create a function that returns the sum of missing numbers from the given array.

Examples

sumMissingNumbers([4, 3, 8, 1, 2]) ➞ 18
// 5 + 6 + 7 = 18

sumMissingNumbers([17, 16, 15, 10, 11, 12]) ➞ 27
// 13 + 14 = 27

sumMissingNumbers([1, 2, 3, 4, 5]) ➞ 0
// No Missing Numbers (i.e. all numbers in [1, 5] are present in the list)

Notes

The numerical range to consider when searching for the missing numbers in the array is the sequence of consecutive numbers between the minimum and maximum of the numbers (inclusive).

sumMissingNumbers
Number of Boomerangs by Helen Yu
Details

A boomerang is a V-shaped sequence that is either upright or upside down. Specifically, a boomerang can be defined as: sub-array of length 3, with the first and last digits being the same and the middle digit being different.

Some boomerang examples:

[3, 7, 3], [1, -1, 1], [5, 6, 5]

Create a function that returns the total number of boomerangs in an array.

To illustrate:

[3, 7, 3, 2, 1, 5, 1, 2, 2, -2, 2]
// 3 boomerangs in this sequence:  [3, 7, 3], [1, 5, 1], [2, -2, 2]

Be aware that boomerangs can overlap, like so:

[1, 7, 1, 7, 1, 7, 1]
// 5 boomerangs (from left to right): [1, 7, 1], [7, 1, 7], [1, 7, 1], [7, 1, 7], and [1, 7, 1]

Examples

countBoomerangs([9, 5, 9, 5, 1, 1, 1]) ➞ 2

countBoomerangs([5, 6, 6, 7, 6, 3, 9]) ➞ 1

countBoomerangs([4, 4, 4, 9, 9, 9, 9]) ➞ 0

Notes

[5, 5, 5] (triple identical digits) is NOT considered a boomerang because the middle digit is identical to the first and last.

let arr = [

]
countBoomerangs
Tower of Hanoi by Ruud Peter Boelens
Details

There are three towers. The objective of the game is to move all the disks over to tower #3, but you can't place a larger disk onto a smaller disk. To play the game or learn more about the Tower of Hanoi, check the Resources tab.

Tower of Hanoi

Create a function that takes a number discs as an argument and returns the minimum amount of steps needed to complete the game.

Examples

towerHanoi(3) ➞ 7

towerHanoi(5) ➞ 31

towerHanoi(0) ➞ 0

Notes

  • The amount of discs is always a positive integer.
  • 1 disc can be changed per move.
towerHanoi
Layers in a Rug by Helen Yu
Details

Write a function that counts how many concentric layers a rug has.

Examples

countLayers([
  "AAAA",
  "ABBA",
  "AAAA"
]) ➞ 2

countLayers([
  "AAAAAAAAA",
  "ABBBBBBBA",
  "ABBAAABBA",
  "ABBBBBBBA",
  "AAAAAAAAA"
]) ➞ 3

countLayers([
  "AAAAAAAAAAA",
  "AABBBBBBBAA",
  "AABCCCCCBAA",
  "AABCAAACBAA",
  "AABCADACBAA",
  "AABCAAACBAA",
  "AABCCCCCBAA",
  "AABBBBBBBAA",
  "AAAAAAAAAAA"
]) ➞ 5

Notes

  • Multiple layers can share the same component so count them separately (example #2).
  • Layers will be horizontally and vertically symmetric.
  • There will be at least one layer for each rug.
const rug1 = [

]
countLayers;
const rug2 = [

]
countLayers;
RegEx: Character Classes X ⁠- \W by Isaac Pak
Details

You can think of character classes as characters with special meaning. They are recognized as special when you place the \ before the character.

Here are a list of the characters classes in JavaScript:

., \cX, \d, \D, \f, \n, \r, \s, \S, \t, \v, \w, \W, \0, \xhh, \uhhhh, \uhhhhh, [\b]

HTML elements are everything from the start tag to the end tag. An example of one div element would be: <div>edabit</div>.

Find out how many <div> elements are used in a string. Use the character class \W in your expression.

Example

const str = "<div>Hello.</div><div>My name is <b>George</b>.</div>"
// 2 times

const str = "<div><h1>The Word for Today</h1><div>aardvark</div></div>"
// 2 times

const str = "<div></div>"
// 1 time

Notes

Check the Resources tab for details on character classes if you're stuck.

const str1 =
;
pakTestExp
const str2 =
;
pakTestExp
const str3 = ; pakTestExp
Positive Dominant by Helen Yu
Details

An array is positive dominant if it contains strictly more unique positive values than unique negative values. Write a function that returns true if an array is positive dominant.

Examples

isPositiveDominant([1, 1, 1, 1, -3, -4]) ➞ false
// There is only 1 unique positive value (1).
// There are 2 unique negative values (-3, -4).

isPositiveDominant([5, 99, 832, -3, -4]) ➞ true

isPositiveDominant([5, 0]) ➞ true

isPositiveDominant([0, -4, -1]) ➞ false

Notes

0 counts as neither a positive nor a negative value.

isPositiveDominant; isPositiveDominant;
Seven Boom! by Alon
Details

Create a function that takes an array of numbers and return "Boom!" if the digit 7 appears in the array. Otherwise, return "there is no 7 in the array".

Examples

sevenBoom([1, 2, 3, 4, 5, 6, 7]) ➞ "Boom!"
// 7 contains the number seven.

sevenBoom([8, 6, 33, 100]) ➞ "there is no 7 in the array"
// None of the items contain 7 within them.

sevenBoom([2, 55, 60, 97, 86]) ➞ "Boom!"
// 97 contains the number seven.

Notes

N/A

sevenBoom simpleSevenBoom // Bonus! getDigits
How Many Days Between Two Dates by Alon
Details

Create a function that takes two dates and returns the number of days between the first and second date.

Examples

getDays(
  new Date("June 14, 2019"),
  new Date("June 20, 2019")
) ➞ 6


getDays(
  new Date("December 29, 2018"),
  new Date("January 1, 2019")
) ➞ 3
// Dates may not all be in the same month/year.


getDays(
  new Date("July 20, 2019"),
  new Date("July 30, 2019")
) ➞ 10

Notes

N/A

const [date1,date2] = [

]
getDays
Oddish vs. Evenish by Helen Yu
Details

Create a function that determines whether a number is Oddish or Evenish. A number is Oddish if the sum of all of its digits is odd, and a number is Evenish if the sum of all of its digits is even. If a number is Oddish, return "Oddish". Otherwise, return "Evenish".

For example, oddishOrEvenish(121) should return "Evenish", since 1 + 2 + 1 = 4. oddishOrEvenish(41) should return "Oddish", since 4 + 1 = 5.

Examples

oddishOrEvenish(43) ➞ "Oddish"
// 4 + 3 = 7
// 7 % 2 = 1

oddishOrEvenish(373) ➞ "Oddish"
// 3 + 7 + 3 = 13
// 13 % 2 = 1

oddishOrEvenish(4433) ➞ "Evenish"
// 4 + 4 + 3 + 3 = 14
// 14 % 2 = 0

Notes

N/A

oddishOrEvenish

Kay, let's just move on.

Very Hard

Mutations Only: Zeroes to the End by Mubashir Hassan
Details

Write a function that moves all the zeroes to the end of an array. Do this without returning a copy of the input array.

Examples

zeroesToEnd([1, 2, 0, 0, 4, 0, 5]) ➞ [1, 2, 4, 5, 0, 0, 0]

zeroesToEnd([0, 0, 2, 0, 5]) ➞ [2, 5, 0, 0, 0]

zeroesToEnd([4, 4, 5]) ➞ [4, 4, 5]

zeroesToEnd([0, 0]) ➞ [0, 0]

Notes

  • You must mutate the original array.
  • Keep the relative order of the non-zero elements the same.
zeroesToEnd
Molar Mass of Chemical Compound by BijogFc24
Details

Create a function that takes a name of a chemical compound as a string and returns the molar mass of the compound. For this challenge only, required data is included below.

Data

H -> 1
B -> 10
O -> 16
S -> 32
N -> 14
Cl -> 35

Water = "H2 O"
BoricAcid = "H3 B O3"
SulfuricAcid = "H2 S O4"
NitricAcid = "H N O3"
HydroChloricAcid = "H Cl"

Examples

molarMass("SulfuricAcid") -> "H2 S O4"
#H * 2 + S * 1 +  O * 4 -----> 1 * 2 + 32 * 1 + 16 * 4 = 98

molarMass("Water") -> "H2 O"
#H * 2 +  O * 1 -----> 1 * 2 + 16 * 1 = 18

Notes

  • Input is a string and return value is number.
  • In the data, "O" is an English letter, not zero.
  • Check out the Resources tab.
molarMass
Recursion: Case and Index Inverter by Deep Xavier
Details

Write a recursive function that takes a string input and returns the string in a reversed case and order.

Examples

invert("dLROW YM sI HsEt") ➞ "TeSh iS my worlD"

invert("ytInIUgAsnOc") ➞ "CoNSaGuiNiTY"

invert("step on NO PETS") ➞ "step on NO PETS"

invert("XeLPMoC YTiReTXeD") ➞ "dExtErIty cOmplEx"

Notes

  • No empty strings and will not contain special characters or punctuation.
  • You are expected to solve this challenge via recursion.
  • You can check on the Resources tab for more details about recursion.
  • An iterative version of this challenge can be found via this link.
  • A collection of challenges in recursion can be found via this link.
invert recursiveInvert
Validating a Set in the Set Game by Helen Yu
Details

In the game Set, three cards form a set if each of the cards are identical or completely different for each of the four properties. All three cards must:

  1. Have the same color or different colors.
  2. Have the same number or different numbers.
  3. Have the same shades or different shades.
  4. Have the same shape or different shapes.

The four properties are:

  1. Colors: red, purple, green
  2. Numbers: 1, 2, 3
  3. Shades: empty, lined, full
  4. Shapes: squiggle, oval, diamond

Here, a set is represented by an array containing three cards. Each card is represented by an object of properties and values. Write a function that determines whether three cards constitute a valid set.

Here is an example of a set:

[
  { color: "red", number: 1, shade: "empty", shape: "squiggle" },
  { color: "red", number: 2, shade: "lined", shape: "diamond" },
  { color: "red", number: 3, shade: "full", shape: "oval" }
]

// "Same" properties: color
// "Different" properties: numbers, shading and shapes

The following is not a set:

[
  { color: "red", number: 1, shade: "empty", shape: "squiggle" },
  { color: "red", number: 2, shade: "lined", shape: "diamond" },
  { color: "purple", number: 3, shade: "full", shape: "oval" }
]

// Colors are not all identical, but not all different.

Examples

isSet([
  { color: "green", number: 1, shade: "empty", shape: "squiggle" },
  { color: "green", number: 2, shade: "empty", shape: "diamond" },
  { color: "green", number: 3, shade: "empty", shape: "oval" }
]) ➞ true

isSet([
  { color: "purple", number: 1, shade: "full", shape: "oval" },
  { color: "green", number: 1, shade: "full", shape: "oval" },
  { color: "red", number: 1, shade: "full", shape: "oval" }
]) ➞ true

isSet([
  { color: "purple", number: 3, shade: "full", shape: "oval" },
  { color: "green", number: 1, shade: "full", shape: "oval" },
  { color: "red", number: 3, shade: "full", shape: "oval" }
]) ➞ false

Notes

  • A set cannot have 2/3 cards having the same property. Either all must share that property, or none will share that particular property.
  • You can play Set by checking the Resources tab.
const cards = [

]
isSet;
Spotlight Map by ohoboho
Details

Given a grid of numbers, return a grid of the Spotlight Sum of each number. The spotlight sum can be defined as the total of all numbers immediately surrounding the number on the grid, including the number in the total.

Examples

spotlightMap([
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9]
]) ➞ [
  [12, 21, 16],
  [27, 45, 33],
  [24, 39, 28]
]


spotlightMap([
  [2, 6, 1, 3, 7],
  [8, 5, 9, 4, 0]
]) ➞ [
  [21, 31, 28, 24, 14],
  [21, 31, 28, 24, 14]
]


spotlightMap([[3]]) ➞ [[3]]

Notes

  • Note that all numbers have a spotlight sum, including numbers on the edges.
  • All inputs will be valid grid (all rows will have the same length).
const grid = [

]
spotlightMap;