-7

Let's say I have:

string1 = "abcdefgh"
string2 = "abb" 

I want to compare all the characters in string2 and check they are represented in string1

Examples:

// Example 1
string1 = "abcdefgh"
string2 = "abb" 
// -->TRUE (even though "b" is used twice it checks it twice to make sure")

// Example 2
string1 = "abcdefgh"
string2 = "abz"
// FALSE ("z" is not represented in string1)

// Example 3
string1 = "abcdefgh"
string2 = "ddd"
// TRUE

// Example 4
string1 = "abcdefgh"
string2 = "xyz"
// FALSE

Thank kindly

Mister Jojo
  • 20,093
  • 6
  • 21
  • 40
  • 3
    You told us what you want, but didn't ask a question. What is the code you wrote, and what problem do you have with it? Please [edit] your question to include your attempt, and explain where you're stuck solving this exercise. – Bergi Jul 08 '22 at 22:54
  • `Member for 6 years, 4 months` seriously ? – Mister Jojo Jul 08 '22 at 22:57
  • You may want to review the following: https://stackoverflow.com/questions/38811421/how-to-check-if-an-array-is-a-subset-of-another-array-in-javascript – PM 77-1 Jul 08 '22 at 22:58
  • 2
    Stack Overflow is not a code-on-demand service, where work orders are given and people code for you. Someone may very well answer this question before it gets closed, but it reduces the site's usefulness for everyone when they do. – Mister Jojo Jul 08 '22 at 22:59

1 Answers1

1

this should solve

const string1 = "abcdefgh"

const string2 = "abb"

const result = string2.split('').every(letter => string1.includes(letter))
console.log(result)

transform string2 into array validates if any item in the array is in string1

EvoluWil
  • 111
  • 3