All programming languages have an implementation of ordered lists, they can be strings arrays vectors, each of which can be a static size or change dynamically, here are some common operations and their function names in some popular languages
Note: I find this as a handy reference instead of looking up the same questions on the internet over and over again.
finding
find the first index of search query
- python:
>>> ["foo", "bar", "baz"].index("bar")
1
const array1 = [5, 12, 8, 130, 44];
const isLargeNumber = (element) => element > 13;
console.log(array1.findIndex(isLargeNumber));
// Expected output: 3
find the last index of search query in string
- javascript
let text = "Hello planet earth, you are a great planet.";
let result = text.lastIndexOf("planet");
// result is 36 and not 5
substrings
slicing
- python:
>>> b = "Hello, World!"
>>> print(b[2:5])
llo
const str = 'The quick brown fox jumps over the lazy dog.';
console.log(str.slice(31));
// Expected output: "the lazy dog."
console.log(str.slice(4, 19));
// Expected output: "quick brown fox"
console.log(str.slice(-4));
// Expected output: "dog."
console.log(str.slice(-9, -5));
// Expected output: "lazy"
contains element
- javascript:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.includes("Mango"); // returns true