From d4e29ce60baa240f166bcbb7939eaeb883cc1239 Mon Sep 17 00:00:00 2001 From: atom-box Date: Thu, 9 Sep 2021 13:31:59 -0500 Subject: [PATCH] Works: run a recursive loop to repeat ever smaller chunks of front. --- helpers/quilt/repeatFront.mjs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/helpers/quilt/repeatFront.mjs b/helpers/quilt/repeatFront.mjs index 4bcbd04..d88b582 100644 --- a/helpers/quilt/repeatFront.mjs +++ b/helpers/quilt/repeatFront.mjs @@ -1,16 +1,24 @@ -const repeatFront = (a, b) => { - return a + b; -} - - +let repeatFront = (s, i) => { + if (typeof s !== 'string'){ + return 'Try again: please enter a word'; + } + if (s.length < 7){ + return `${s.length} is too short`; + } + // take a chunk of the front + let firstBite = s.slice(0, i); -// repeatFront.js -// const price = document.querySelector('#price'); -// const output = document.querySelector('.price-output'); + // recursive + let layBricks = (fragment) => { + if (fragment.length <= 1) { + return fragment; + } + was = fragment; + fragment = fragment.slice(0, fragment.length - 1); + console.log('was length ' + was.length + 'frag length: ' + fragment.length); + return was + layBricks(fragment); + } -// output.textContent = price.value; - -// price.addEventListener('input', function() { -// output.textContent = price.value; -// }); \ No newline at end of file + return layBricks(firstBite); +}