freeCodeCamp/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations.md
Anna 6fa282cb6f
Some checks failed
i18n - Build Validation / Validate i18n Builds (20.x) (push) Has been cancelled
CI - Node.js / Lint (20.x) (push) Has been cancelled
CI - Node.js / Build (20.x) (push) Has been cancelled
CI - Node.js / Test (20.x) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (20.x) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 20.x) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 20.x) (push) Has been cancelled
i18n - Download Client UI / Client (push) Has been cancelled
chore(curriculum): update asserts in legacy basic algorithm scripting (#57784)
Co-authored-by: Naomi <accounts+github@nhcarrigan.com>
2025-01-04 13:10:00 +01:00

2.3 KiB

id title challengeType forumTopicId dashedName
af2170cad53daa0770fabdea Mutations 1 16025 mutations

--description--

Return 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 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.

--hints--

mutation(["hello", "hey"]) should return false.

assert.isFalse(mutation(['hello', 'hey']));

mutation(["hello", "Hello"]) should return true.

assert.isTrue(mutation(['hello', 'Hello']));

mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"]) should return true.

assert.isTrue(mutation(['zyxwvutsrqponmlkjihgfedcba', 'qrstu']));

mutation(["Mary", "Army"]) should return true.

assert.isTrue(mutation(['Mary', 'Army']));

mutation(["Mary", "Aarmy"]) should return true.

assert.isTrue(mutation(['Mary', 'Aarmy']));

mutation(["Alien", "line"]) should return true.

assert.isTrue(mutation(['Alien', 'line']));

mutation(["floor", "for"]) should return true.

assert.isTrue(mutation(['floor', 'for']));

mutation(["hello", "neo"]) should return false.

assert.isFalse(mutation(['hello', 'neo']));

mutation(["voodoo", "no"]) should return false.

assert.isFalse(mutation(['voodoo', 'no']));

mutation(["ate", "date"]) should return false.

assert.isFalse(mutation(['ate', 'date']));

mutation(["Tiger", "Zebra"]) should return false.

assert.isFalse(mutation(['Tiger', 'Zebra']));

mutation(["Noel", "Ole"]) should return true.

assert.isTrue(mutation(['Noel', 'Ole']));

--seed--

--seed-contents--

function mutation(arr) {
  return arr;
}

mutation(['hello', 'hey']);

--solutions--

function mutation(arr) {
  let hash = Object.create(null);

  arr[0]
    .toLowerCase()
    .split('')
    .forEach(c => (hash[c] = true));

  return !arr[1]
    .toLowerCase()
    .split('')
    .filter(c => !hash[c]).length;
}

mutation(['hello', 'hey']);