Given a string nums that contains only digits and an array of numbers predefinedNumbers, I have to add colons in nums to construct a new string, where each number between colons has to be a valid number from predefinedNumbers and return all possibilities
EX: nums = “143163421154143” predefinedNumbers = [“21154”, “143”, “21154143”, “1634”, “163421154”]
Output: [ “:143:1634:21154:143:”, “:143:163421154:143:”, “:143:1634:21154143:” ]
So far I tried this code but it’s not the result I need and I’m stuck trying to understand how to go over it recursively.
Any hint is very much appreciated.
let nums = "143163421154143";
predefinedNumbers = ["21154", "143", "21154143", "1634", "163421154"];
let newArray=[];
function makeNumSentences (nums, predefinedNumbers) {
predefinedNumbers.map(item => {
if (nums.includes(item)) {
newArray.push(item)
}
})
console.log(newArray.join(':'));
};
makeNumSentences("143163421154143",["21154", "143", "21154143", "1634", "163421154"])