CoDEVIANT #9 (3/31/19)

Problem #1: String ends with?


Complete the solution so that it returns true if the first argument(string) passed in ends with the 2nd argument (also a string).


solution(‘abc’, ‘bc’) // returns truesolution(‘abc’, ‘d’) // returns false

How Adrian Solved It:

Truth be told I didn’t do any of that shit. Peyote is fun for normos, but your guy’s drug of choice is rat poison. Rat’s aren’t dumb, they eat pizza, hot dogs, know to dumpster dive…that’s like your typical undergrad student the way Sallie Mae is about blowing up peoples’ phones these days.

How Adrian Actually Solved It:

function solution(str, ending){   return str.slice(-ending.length) == ending ? true: false;}

That’s it. It’s actually a stupidly simple problem. But here goes. So str is always going to be longer than ending. That said, we want to know if ending is going to be the same as the end of str. To do this, we use a ternary operator phrase to return true or false.


If it turns out to be true that getting the length of the ending and slicing the negative number of that length from str with .slice( ) and seeing if it is the same as ending

In this case, we’ll land with true.


If the final part of str does not equal ending, then we just return false.

“Best Practices” Solution:

function solution(str, ending){ 
return str.endsWith(ending);

Okay…well apparently there is a string method called endsWith( ) and you can pass in what you want to evaluate the ending of str against…and that’s it. It’s a good thing I didn’t whip up some weird thing that used splitting into an array 😅😅😅 *Yeah, I’m TOTES competent*

Problem 2: Multiplication Tables


I managed to solve this one. Let me preface this by saying that I am wwaaaaaaaayyyyy too inebriated to be able to figure this out. That I did and in such a short time is kind of hacks to me. I don’t know if there’s something in the water or what.


Create a function that accepts dimensions, of Rows x Columns, as parameters in order to create a multiplication table sized according to the given dimensions. **The return value of the function must be an array, and the numbers must be Fixnums, NOT strings.


multiplication_table(3,3)1 2 32 4 63 6 9→[[1,2,3],[2,4,6],[3,6,9]]

Each value on the table should be equal to the value of multiplying the number in its first row times the number in its first column.

How Adrian Solved it while intoxicated:

function multiplicationTable(row,col){let answer = [];let rowArray;for(let i = 1; i <= row ; i++ ){rowArray = [];for(let c = 1; c <= col ; c++){rowArray.push(c*i);}answer.push(rowArray);}return answer;}

“Best Practices Answer”:

function multiplicationTable(row,col){out = []for (var i = 1; i <= row; i++) {temp = []// console.log(temp)for (var j = 1; j <= col; j++) {temp.push(i*j)} out.push(temp)} return out}

They’re about the same. they declared temp inside of a for=loop. I had my version, rowArray be instantiated outside of the for loops.

Cool ;)



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store