CoDEVIANT #5 (3/25/19)

Problem 1: Best travel

“What MAN wrote this?!” — Paula
  • Get mini 3-length arrays that are unique combinations of the full list of distances
  • We need to get sums of distances from these mini arrays
  • The distance we can accept must be smaller than whatever value is represented by the argument t
function chooseBestSum(t, k, ls) {   var biggestCount = 0;   var recurseTowns = function(townsSoFar, lastIndex) {   townsSoFar = townsSoFar || [];   //base case   if (townsSoFar.length === k) {      var sumDistance = townsSoFar.reduce((a,b)=>a+b);         if (sumDistance <= t && sumDistance > biggestCount) {            biggestCount = sumDistance;         }      return; //EJECT   }//recursive case   for (var i = lastIndex + 1 || 0; i < ls.length; i++) {      recurseTowns(townsSoFar.concat(ls[i]), i);   }}recurseTowns();return biggestCount || null;}
When
coding stops
being cute & fun.
  • Dress me up in blue; crip-style.
  • Put my H&K 9mm USP with a tac-light & a silencer in my hand just like in MGS2.
  • I want gold chains with lots of bling around me.
  • Studded grills too.
  • Make sure my fingers rigor mortis up in a crip-sign.
Bury me in this.
Xzibit couldn’t come here today, so I did.
var action = function(arguments) {//stuff that we do}this is pretty uncommon
--------------------------------
function action(arguments){//stuff that we do}
you’ll typically see this a lot more often
  • townsSoFar
  • lastIndex
and cry, cry, cry, like a TEN YEAR OLD GIRL!
townsSoFar = townsSoFar || [];//townsSoFar equals itself and if itself doesn’t exist, then make it an empty array.
  • IF sumDistance is less than-or-equal to the amount of miles the couple agreed to travel, t, AND sumDistance is larger than biggestCount
  • then biggestCount will equal the value of sumDistance.
…its not up to you!
function chooseBestSum(t, k, ls) {   var biggestCount = 0;   var recurseTowns = function(townsSoFar, lastIndex) {   townsSoFar = townsSoFar || [];   //base case   if (townsSoFar.length === k) {      var sumDistance = townsSoFar.reduce((a,b)=>a+b);         if (sumDistance <= t && sumDistance > biggestCount) {            biggestCount = sumDistance;         }      return; //EJECT   } else {     //recursive case     for (var i = lastIndex + 1 || 0; i < ls.length; i++) {        recurseTowns(townsSoFar.concat(ls[i]), i);     }   }}recurseTowns();return biggestCount || null;}
//What it calls for → recurseTowns(townsSoFar , lastIndex)//what it looks like at this point ↓recurseTowns(townsSoFar.concat(ls[i]), i);[] -> [‘666’] , 0//whatever value lives at ls[i] will be shoved into townsSoFar
Is it the kth time yet?
the code// recurseTowns(townsSoFar.concat(ls[i]), i);the first time// recurseTowns(townsSoFar.concat(ls[0]), 0); // lets assume ls[0] equals 666.this time// recurseTowns(townsSoFar.concat(ls[1]), 1); //let’s assume ls[1] equals 40.

This means that the variable townsSoFar now looks like the following = [666, 40]

return biggestCount || null; // return biggestCount or return null;
all of this…because two assholes can’t drive.
I LOVE this scene…
  • biggestCount (or Sati creating a new world, with Oracle & Architect saying stuff.
  • null (with Smith destroying everything).
…and eating all the pizza.
domainName(“http://github.com/carbonfive/raygun") == “github”domainName(“http://www.zombie-bites.com") == “zombie-bites”domainName(“https://www.cnet.com") == “cnet”
Test.assertEquals(domainName(“http://google.com"), “google”);Test.assertEquals(domainName(“http://google.co.jp"), “google”);Test.assertEquals(domainName(“www.xakep.ru"), “xakep”);Test.assertEquals(domainName(“https://youtube.com"), “youtube”);
function domainName(url){//We need to strip away http:// or https:////We need to strip away www.//then if there is anything that comes after a “ . “ we need to get rid of all of that and the period too.console.log(url);   switch(url.includes(‘https://')) {      case true:        url = url.replace(‘https://','');        break;      default:        url = url.replace(‘http://','');   }   switch(url.includes(‘www.')){      case true:         url = url.replace(‘www.','');      break;      default:      break;   }//make into an array, find where the ‘.’ is and delete it and everything past it.   return url.split(‘.’)[0]}
  • Cut away https:// or http://
  • Cut away www.
  • If there is anything after “ . “ we want to delete that shit.
var string = “pizza”;string.includes(‘c’); // returns ‘false’string.includes(‘z’); // returns ‘true’
var string = “Cat Hate”;string.replace(“Hate”, “Love”) // we get string equalling “Cat Love”.
switch(url.includes(‘www.')){   case true:      url = url.replace(‘www.','');   break;   default:   break;}
var word = ‘pizza’;word = word.split(‘p’);console.log(word); // [‘’,’izza’]
We’re basically just Thanos-ing the fuck out over err’thang in this bitch.
var url = google.comurl.split(‘.’) // [‘google’, ‘com’];                   url[0]    url[1]So url[0] would be ‘google’and url[1] would be ‘com’So let’s just cut out the middle man/extra steps and return url[0].return url.split(‘.’)[0]
function domainName(url){   url = url.replace(“https://”, ‘’);   url = url.replace(“http://”, ‘’);   url = url.replace(“www.”, ‘’);  return url.split(‘.’)[0];};

--

--

--

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

The Primitives Needed to Power a Complete DeFi Ecosystem

5 Type of Http States Codes

How to be a great engineer!

Draft — Educational Code : How to write code that tells a story

5 Mistakes Every Self-taught Programmer Should Avoid.

Android fundamentals 05.3: Adaptive layouts

DevOps 101: Git Branching

Authenticate Azure Data Factory with Azure Data Lake Gen 2 using Managed Identities

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

Frontend Versus backend for dummies

What is git and how does it work?

A Little Bit Easier with Each Step…

JavaScript Simplified — A Beginner’s Guide