Right substring generator

JavaScript, String, Generator · Jul 25, 2022

Generates all right substrings of a given string.

const rightSubstrGenerator = function* (str) {
  if (!str.length) return;
  for (let i in str) yield str.slice(-i - 1);
// [ 'o', 'lo', 'llo', 'ello', 'hello' ]

Written by Angelos Chalaris

I'm Angelos Chalaris, a JavaScript software engineer, based in Athens, Greece. The best snippets from my coding adventures are published here to help others learn to code.

If you want to keep in touch, follow me on GitHub.

More like this

  • JavaScript Generator Functions

    JavaScript generator functions are an advanced yet very powerful ES6 feature, which you can start using in your code right now.

    Collection · 17 snippets

  • Left substring generator

    Generates all left substrings of a given string.

    JavaScript, String · Jul 24, 2022

  • Index of substrings

    Finds all the indexes of a substring in a given string.

    JavaScript, String · Dec 31, 2020

  • String ends with substring

    Checks if a given string ends with a substring of another string.

    JavaScript, String · Aug 1, 2022