CoDEVIANT #9 (3/31/19)

solution(‘abc’, ‘bc’) // returns truesolution(‘abc’, ‘d’) // returns false
  • I took a look at the problem and began to meditate.
  • Then I lost focus and realized that I was more likely to succeed if I got some spiritual guidance.
  • I took some Peyote and wandered into the forest to meet my spirit animal to see if she could help me connect with some way to talk to computers.
  • Eventually, she sat me down, and told me to read the docs.
function solution(str, ending){   return str.slice(-ending.length) == ending ? true: false;}
function solution(str, ending){ 
return str.endsWith(ending);
}
multiplication_table(3,3)1 2 32 4 63 6 9→[[1,2,3],[2,4,6],[3,6,9]]
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;}
  • So…we decide we’re going to have a variable called answer that will be an empty array.
  • Then we allow rowArray to be a bit of a blank slate variable that exists in the scope of our function.
  • Then we create a for loop to go from the start to the end of the number that row represents starting at 1 (and not zero like usual) — We say that we’ll keep going until i is less than or equal to the value that row represents.
  • We make rowArray equal an empty array;
  • We create another for loop to iterate over the path from 1 to whatever number the variable col represents
  • We say that we’ll keep going until c is less than or equal to the value that col represents.
  • If c is equal to 1 and if i is also equal to 1 then you want to push that value of c to rowArray, otherwise you will want to push into rowArray the result of c times i.
  • Within the scope of the first for-loop, the one with i you’ll want to push rowArray into answer this will happen a number of times 😉
  • When all is said and done we just return 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}

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

EAS Build — February Preview Update

Getters and Setters in JavaScript

JavaScript Versions: ES6 and Before

How TypeScript squashed all known bugs

Middleware… Like a sweater?

Binary Search Trees in JavaScript

React Hooks — Part I

Sets and Maps

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
Adrian Rosales

Adrian Rosales

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

More from Medium

Github has You Covered

[Technical Article] Deepin Music — CD Playback

The inspect tool — tips and tricks #4

The value of a key value pair in the inspect tool shown as an object with an easy to read format

Technology is “Forever Learning”