-
Star
(0)
You must be signed in to star a gist -
Fork
(1,162)
You must be signed in to fork a gist
-
-
Save kvirani/c656a532f0330c9fb0b31837eb5876d7 to your computer and use it in GitHub Desktop.
W1D2 - Debugging incorrect code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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