Sunday, September 13, 2026
Latest:
  • Präsentation für b1
  • Verb “werden” Konjugation
  • In German, verb sein (to be) Konjunktion
  • Wichtige wörter für B1 prüfung
  • What are the main differences between ApplicationContext and BeanFactory?
Upokary

Upokary

Quality information

  • Health
  • Life
  • Fashion
  • Food
  • Code
  • English
  • বাংলা
Technology 

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

Published: February 10, 2022Last updated: February 10, 2022
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));

You May Also Like

What are the differences between null and undefined?

August 30, 2021 beroza

Minimum Changes To Make Alternating Binary String

January 11, 2023 beroza
Wi-Fi

What is Wi-Fi? What are the advantages and disadvantages of Wi-Fi?

June 15, 2022 Griza Paul

How to pass an event to parent DOM from Iframe using JavaScript?

November 29, 2020 beroza

How to convert timestamp to date object in JavaScript?

April 15, 2021 beroza

How to check if an element is visible in the current viewport as we scroll?

July 8, 2020 beroza

Write an efficient program to print prime numbers.

November 19, 2021 beroza

How to remove a character from a string using JavaScript?

March 8, 2021 beroza

Difference between session.timeout.ms and max.poll.interval.ms for Kafka

June 9, 2020 beroza

Why Upokary?

Upokary.com is a useful application in everyday life. It provides very handy information regarding every aspect of life. Each and every tip of upokary.com is meant to make life better.

Upokary tools

  • Youtube thumbnail
  • Youtube video downloader

Useful Links

  • Handy code
  • Technology
  • People
  • Programming
  • Quote
  • Travel
  • WordPress
  • IELTS
  • Kids

Pages

  • Sitemap
  • Privacy policy
  • About us
  • Contact us

Support

For any kind of query or question please drop a message in the following email: upokary@gmail.com
Copyright © 2026 Upokary. All rights reserved.