 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Finding matches in two elements JavaScript
We are required to write a function that returns true if the string in the first element of the array contains all of the letters of the string in the second element of the array.
For example,
["hello", "Hello"], should return true because all of the letters in the second string are present in the first, ignoring their case.
The arguments ["hello", "hey"] should return false because the string "hello" does not contain a "y".
Lastly, ["Alien", "line"], should return true because all of the letters in "line" are present in "Alien".
This is a fairly simple problem; we will just split the second element of the array and iterate over the array thus produced to check whether the first element contains all the characters or not.
Example
const arrayContains = ([fist, second]) => {    return second    .toLowerCase()    .split("")    .every(char => {       return fist.toLowerCase().includes(char);    }); }; console.log(arrayContains(['hello', 'HELLO'])); console.log(arrayContains(['hello', 'hey'])); console.log(arrayContains(['Alien', 'line']));  Output
The output in the console will be −
true false true
Advertisements
 