Question
Complete these methods in Javascript you cannot use the pre-built-in in methods in java write it from scratch using the parameters given /** * Returns
Complete these methods in Javascript
you cannot use the pre-built-in in methods in java write it from scratch using the parameters given
/**
* Returns the 1-based position where an object is on this stack.
* If the object o occurs as an item in this stack, this method
* returns the distance from the top of the stack of the occurrence
* nearest the top of the stack; the topmost item on the stack is
* considered to be at distance 1. The equals method is used to
* compare o to the items in this stack.
*
* Example:
*
* s.push(4);
* s.push(5);
* s.push(6);
* s.search(6); // 1
* s.search(5); // 2
* s.search(4); // 3
* s.search(27) // -1
*
* @param o the desired object.
* @return the 1-based position from the top of the stack where the object is located;
* the return value -1 indicates that the object is not on the stack.
*/
public int search(Object o) {
}
/**
* Returns true if this stack contains the specified element.
* More formally, returns true if and only if this stack contains
* at least one element e such that (o==null ? e==null : o.equals(e)).
* @param o element whose presence in this ArrayList is to be tested
* @return true if this ArrayList contains the specified element
*/
public boolean contains(Object o) {
}
/**
* Returns the index of the first occurrence of the specified element in this stack,
* or -1 if this ArrayList does not contain the element. This is the index in the
* underlying ArrayList, NOT the position in the stack as defined in the search
* function. More formally, returns the lowest index i such that (o==null ?
* get(i)==null : o.equals(get(i))), or -1 if there is no such index.
* @param o element to search for
* @return the index of the first occurrence of the specified element in this ArrayList,
* or -1 if this ArrayList does not contain the element
*/
public int indexOf(Object o) {
}
/**
* Returns the index of the last occurrence ;of the specified element in this stack,
* or -1 if this ArrayList does not contain the element. This is the index in the
* underlying ArrayList, NOT the position in the stack as defined in the search
* function. More formally, returns the highest index i such that (o==null ?
* get(i)==null : o.equals(get(i))), or -1 if there is no such index.
* @param o element to search for
* @return the index of the last occurrence of the specified element in this stack
*/
public int lastIndexOf(Object o){
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started