Skip to content

Instantly share code, notes, and snippets.

@kvirani
Forked from hora/print-in-frame.js
Last active March 21, 2024 20:45
Show Gist options
  • Save kvirani/c656a532f0330c9fb0b31837eb5876d7 to your computer and use it in GitHub Desktop.
Save kvirani/c656a532f0330c9fb0b31837eb5876d7 to your computer and use it in GitHub Desktop.
W1D2 - Debugging incorrect code
function printInFrame(list) {
var list = list.split(' ');
var longest = longestStr(list).length;
var border = repeat('*', longest);
console.log(border);
for (word of list) {
console.log('* ' + word + repeat(' ', longest - word.length + 1) + '*');
}
console.log(border);
}
function repeat(str, times) {
var result = str;
for (var i = 0; i < times; i++) {
result += str;
}
return result;
}
function longestStr(list) {
var longest = list[0];
for (str of list) {
longest = str;
}
return longest;
}
// Test driver code, do not modify
printInFrame('May the force be with you');
printInFrame('Here\'s Johnny!');
printInFrame('Supercalifragalisticexpialadocious');
printInFrame('Lost, like tears in the rain');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment