52
loading...
This website collects cookies to deliver better user experience
You solve a problem when given a set of constraints and having to follow some rules you come up with a solution that meets all the constraints and does not break the rules. As programmers, we write a program, a set of instructions that solves the problem.
selectEvenNumbers
that will take in an array of numbers and return an array evenNumbers
of only even numbers. If there are no even numbers, return the empty array evenNumbers
.function selectEvenNumbers() {
// your code here
}
Corner case: a problem or situation that occurs outside of normal operating parameters, specifically when multiple environmental variables or conditions are simultaneously at extreme levels, even though each parameter is within the specified range for that parameter.
Edge case: problem or situation that occurs only at an extreme (maximum or minimum) operating parameter
[1]
[1, 2]
[1, 2, 3, 4, 5, 6]
[-200.25]
[-800.1, 2000, 3.1, -1000.25, 42, 600]
2
,4
,6
, and so on in the array without realizing it. If you're having trouble, consider using massive quantities of data, which will overcome your brain's natural ability to answer the problem simply by looking at it.That helps you work through the real algorithm.[1]
[1]
[1, 2]
[1, 2]
1
2
evenNumbers
and add 2
to this array[2]
[1]
varies slightly from [1, 2]
. That is why I try to go through a couple of different sets. I have some sets with just one element, some with floats instead of just integers, some with multiple digits in an element, and some with negatives just to be safe.selectEvenNumbers
evenNumbers
where I store even numbers, if any[1, 2]
evenNumbers
evenNumbers
, regardless of whether it has anything in it// Initialize a variable with a 'n' value
// Multiply variable by it self
// Return the result of that multiplication
function square(n) {
// Initialize a variable with a 'n' value
const initialValue = n
// Multiply variable by it self
const squaredValue = initialValue * initialValue
// Return the result of that multiplication
return squaredValue
}
function square(n) {
return n * n
}