Skip to content

Instantly share code, notes, and snippets.

@appoll
Created June 2, 2021 16:23
Show Gist options
  • Save appoll/af14f92a0b339e148c8133103726de14 to your computer and use it in GitHub Desktop.
Save appoll/af14f92a0b339e148c8133103726de14 to your computer and use it in GitHub Desktop.
// 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