Problem #1: String ends with?

(https://www.codewars.com/kata/string-ends-with/train/javascript)

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

Examples:

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.

True

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.

False

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

(https://www.codewars.com/kata/multiplication-tables/train/javascript)

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.

Instructions:

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.

Example:

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 ;)

is a web developer, opera singer, actor, and lover of cats. (adrian-rosales.tech)