Skip to content

Commit

Permalink
Works: run a recursive loop to repeat ever smaller chunks of front.
Browse files Browse the repository at this point in the history
  • Loading branch information
atom-box committed Sep 9, 2021
1 parent 1be9dec commit d4e29ce
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions helpers/quilt/repeatFront.mjs
Original file line number Diff line number Diff line change
@@ -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;
// });
return layBricks(firstBite);
}

0 comments on commit d4e29ce

Please sign in to comment.