Contains method is only for html dom to check if html dom has mentioned child, includes is to check if a strong contains a substring.

const array1 = [1, 2, 3];
 
console.log(array1.includes(2));
// Expected output: true
 
const pets = ['cat', 'dog', 'bat'];
 
console.log(pets.includes('cat'));
// Expected output: true
 
console.log(pets.includes('at'));

Chromium Source Code C++ implementation of includes? cppreference.com has this implementation of https://en.cppreference.com/w/cpp/algorithm/ranges/includes

template<[std::input_iterator](http://en.cppreference.com/w/cpp/iterator/input_iterator) I1, [std::sentinel_for](http://en.cppreference.com/w/cpp/iterator/sentinel_for)<I1> S1,
             [std::input_iterator](http://en.cppreference.com/w/cpp/iterator/input_iterator) I2, [std::sentinel_for](http://en.cppreference.com/w/cpp/iterator/sentinel_for)<I2> S2,
             class Proj1 = [std::identity](http://en.cppreference.com/w/cpp/utility/functional/identity), class Proj2 = [std::identity](http://en.cppreference.com/w/cpp/utility/functional/identity),
             [std::indirect_strict_weak_order](http://en.cppreference.com/w/cpp/iterator/indirect_strict_weak_order)<
                 std::[projected](http://en.cppreference.com/w/cpp/iterator/projected)<I1, Proj1>,
                 std::[projected](http://en.cppreference.com/w/cpp/iterator/projected)<I2, Proj2>> Comp = [ranges::less](http://en.cppreference.com/w/cpp/utility/functional/ranges/less)>
    constexpr bool operator()(I1 first1, S1 last1, I2 first2, S2 last2,
                              Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) const
    {
        for (; first2 != last2; ++first1)
        {
            if (first1 == last1 || comp(*first2, *first1))
                return false;
            if (!comp(*first1, *first2))
                ++first2;
        }
        return true;
    }

The algorithm used in the provided code is essentially a linear search algorithm. It iterates through the elements of the second range ([first2, last2)) and, for each element, searches for its presence in the first range ([first1, last1)). The search involves comparisons using the specified comparator (comp) and projections (proj1 and proj2).

Here’s a step-by-step breakdown of the algorithm:

  1. Iterate through the elements of the second range ([first2, last2)).
  2. For each element of the second range, iterate through the elements of the first range ([first1, last1)).
  3. Use the provided projection functions (proj1 and proj2) to transform the elements from both ranges before comparison.
  4. Use the specified comparator (comp) to compare the transformed elements.
  5. If an element from the second range is found in the first range (with the correct order according to the comparator), move to the next element in the second range.
  6. If an element from the second range is not found in the first range or if the order is incorrect, return false.
  7. If all elements from the second range are successfully found in the first range in the correct order, return true.

The algorithm has a time complexity of O(N * M), where N is the size of the first range and M is the size of the second range. This is because, in the worst case, it may need to iterate through all elements of both ranges. The actual performance can vary based on the characteristics of the ranges and the efficiency of the comparator.