We Start The Factory

In Santa's workshop, the elves have a list of gifts they wish to make and a limited set of materials.

Gifts are strings of text and the materials are characters. Your task is to write a function that, given a list of gifts and the available materials, returns a list of gifts that can be made.

A gift can be made if we have all the necessary materials to make it.

Source: AdventJS

Author: @Midudev

1const gifts1 = ["tren", "oso", "pelota"];
2const materials1 = "tronesa";
3
4manufacture(gifts1, materials1); // ["tren", "oso"]
5
6const gifts2 = ["juego", "puzzle"];
7const materials2 = "jlepuz";
8
9manufacture(gifts2, materials2); // ["puzzle"]
10
11const gifts3 = ["libro", "ps5"];
12const materials3 = "psli";
13
14manufacture(gifts3, materials3); // []

solution.ts

1function manufacture(gifts: string[], materials: string) {
2 return gifts.filter((g) => g.split("").every((l) => materials.includes(l)));
3}