Created
June 2, 2021 16:23
-
-
Save appoll/af14f92a0b339e148c8133103726de14 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// E5. | |
// Write a function that takes two parameters: an array and a Number; | |
// The function returns the index of | |
// the element's first occurence in the array; | |
// should return position of number in array | |
function findPositionOfNumberInArray(array, number){ | |
// iterate over the array -> for loop | |
// compare the item of each position in the array to the <givenNumber> | |
// -> equality operator === | |
// -> if statement | |
// return the position of the current item | |
// -> return | |
} | |
// BONUS | |
// If the number is not in the array, return the value -1 | |
let a = [15, 16, 17, 15]; | |
let returned = findPositionOfNumberInArray(a, 17); | |
console.log(returned); // Should print 2 | |
returned = findPositionOfNumberInArray(a, 16); | |
console.log(returned); // Should print 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment