Find the segmented input string into the words of a given dictionary.

const findSegment = (dictionary, input) => {
    const result = []
    for(let i = 0; i < input.length; i++) {
        for(let j = i + 1; j <= input.length; j++) {
            const segment = input.slice(i, j);
            if(dictionary.indexOf(segment) > -1) {
                result.push(segment);
            }
        }
    }
    return result
};
const dictionary = ['apple', 'pear', 'pier', 'pie'];
const input = 'applepie';
console.log(findSegment(dictionary, input));