Welcome to Elyses Analytic Enchantments on Exercism's JavaScript Track.
If you need help running the tests or submitting your code, check out HELP.md
.
If you get stuck on the exercise, check out HINTS.md
, but try and solve it without using those first :)
In JavaScript, an array is a list-like structure with no fixed length which can hold any type of primitives or objects, or even mixed types. The array elements can be accessed by their index. Arrays are also given a bunch of built-in methods. Some of these built-in methods can analyse the contents of the array. Many of the built-in functions that analyse the contents of an array, take a predicate
as argument.
The built-in functions are meant to be used instead of a for
loop or the built-in Array#forEach()
:
Example of analysis using a for loop :
const numbers = [1, 'two', 3, 'four'];
for (var i = 0; i < numbers.length; i++) {
if (numbers[i] === 'two') {
return i;
}
}
// => 1
Example of analysis using a built-in method:
const numbers = [1, 'two', 3, 'four'];
numbers.indexOf('two');
// => 1
Elyse, magician-to-be, continues her training. She will be given several stacks of cards that she needs to perform her tricks. To make things a bit easier, she only uses the cards 1 to 10.
In this exercise, use built-in methods to analyse the contents of an array.
Elyse wants to know the position (index) of a card in the stack.
const card = 2;
getCardPosition([9, 7, 3, 2], card);
// => 3
Elyse wants to determine if a card is present in the stack -- in other words, if the stack contains a specific number
.
const card = 3;
doesStackIncludeCard([2, 3, 4, 5], card);
// => true
Elyse wants to know if every card is even -- in other words, if each number in the stack is an even number
.
isEachCardEven([2, 4, 6, 7]);
// => false
Elyse wants to know if there is an odd number in the stack.
doesStackIncludeOddCard([3, 2, 6, 4, 8]);
// => true
Elyse wants to know the value of the first card that is odd.
getFirstOddCard([4, 2, 8, 7, 9]);
// => 7
Elyse wants to know the position of the first card that is even.
getFirstEvenCardPosition([5, 2, 3, 1]);
// => 1
- @peterchu999
- @SleeplessByte