Word Nest (Code Challenge)

  • Page Owner: Not Set
  • Last Reviewed: 2020-01-03

Word Nests

A word nest is created by taking a starting word, and generating a new string by placing the word inside itself. This process is then repeated.

Nesting 3 times with the word "incredible":

start  = incredible
first  = incre|incredible|dible
second = increin|incredible|credibledible
third  = increinincr|incredible|ediblecredibledible
The final nest is "increinincrincredibleediblecredibledible" (depth = 3).

Given a starting word and the final word nest, return the depth of the word nest.

Examples

wordNest("floor", "floor") ➞ 0

wordNest("code", "cocodccococodededeodeede") ➞ 5

wordNest("incredible", "increinincrincredibleediblecredibledible") ➞ 3

Notes

N/A

Tests

Test = (x, y) => x == y ? console.log("Pass", "Yours", x, "Correct:", y) || true : console.log("Fail", "Yours", x, "Correct:", y) || false;

wordNest = () => !1;

Test(wordNest("engagement", "engenengagemengagemeengagementntentgagementagement"), 4)
Test(wordNest("passage", "passpassageage"), 1)
Test(wordNest("factory", "ffacfactofactfafactoryctoryoryrytoryactory"), 5)
Test(wordNest("deny", "ddededdddenyenyenyenynynyeny"), 6)
Test(wordNest("jinx", "jijijjijjijijjinxinxnxnxinxnxinxnxnx"), 8)
Test(wordNest("deal", "dedddealealealal"), 3)
Test(wordNest("paradox", "parparaparadoxdoxadox"), 2)
Test(wordNest("meet", "mmememmeeteeteteteet"), 4)
Test(wordNest("last", "lalastst"), 1)
Test(wordNest("silence", "sisilsisilencelenceencelence"), 3)
Test(wordNest("inflate", "inflate"), 0)
Test(wordNest("ruin", "rurrurrrrrrururuinininuinuinuinuinuininuinin"), 10)
Test(wordNest("episode", "episoepisepisepiepiepiepisoepisodedesodesodesodeodeodede"), 7)
Test(wordNest("dictate", "dictadicdidictdiddictadictadictateteteictatectateatectatetatete"), 8)
Test(wordNest("caller", "callcacacalccallcacaccallerallerllerllererallerlerllerllerer"), 9)
Test(wordNest("sweater", "sweatsweswsweatereateraterer"), 3)
Test(wordNest("measure", "measumememeasumemmeasmmeasureeasureureeasureasurereasureasurere"), 8)
Test(wordNest("relieve", "relierelierelrelierrelieveelieveveieveveve"), 5)
Test(wordNest("home", "hohohohhohohhhohhomeomemeomeomememeomemememe"), 10)
Test(wordNest("profession", "profesprofessionsion"), 1)
Test(wordNest("continuous", "contcontcontinuoconcocontinuousntinuoustinuoususinuousinuous"), 5)