Sunday, October 5, 2025
Latest:
  • German Pronouns with Nominative, Accusative, and Dative cases
  • German articles for the nominative, accusative, and dative cases
  • Der kleine Vogel und die Sonne
  • German alphabet pronunciation
  • Command design pattern
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 is useRef in React? What are the use cases of useRef?

August 14, 2021 beroza

What are the differences between application server and a servlet container?

November 25, 2019 beroza

JavaScript tips for problem solving

June 11, 2023 beroza

What is Java annotation? Write some facts about Java annotation

January 25, 2019 beroza

cannot load such file — openssl when try to install gem install rails

May 20, 2020 beroza

How Jenkins X works with Kubernetes using PROW and Tekton?

May 13, 2020 beroza

Why useState is asynchronous in ReactJS?

January 1, 2021 beroza

Construct the Smallest Number From DI String

January 10, 2023 beroza

dyld: Library not loaded, Referenced from: Reason: image not found

May 20, 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 © 2025 Upokary. All rights reserved.