CoDEVIANT #7 (3/27/19)

L = {“ABART 20”, “CDXEF 50”, “BKWRK 25”, “BTSQZ 89”, “DRTYM 60”}.
L = [“ABART 20”, “CDXEF 50”, “BKWRK 25”, “BTSQZ 89”, “DRTYM 60”]
M = {“A”, “B”, “C”, “W”}
M = [“A”, “B”, “C”, “W”] or …
(A : 20) — (B : 114) — (C : 50) — (W : 0)

Note:

function stockList(listOfArt, listOfCat){// …}
  • So we’re going to make a variable called answer that we will eventually return.
  • It will be an empty string
let answer = ‘’;
  • Make an object that would hold the capitalized first letter of the category as keys.
let object = {};
  • Then do some magic to get the vaules of the listOfCat array to become keys for the object we just made
  • We create a for loop where we iterate over the listOfCat array’s length and create object key/value pairs with the key being set with object[listOfCat[i]] (where i represents the index of the array element we are on) and the value being hardcoded at zero.
for (var i=0; i < listOfCat.length; i++) {object[listOfCat[i]] = 0;};
  • If we were to console.log our object variable right now and we had started with a listOfCat argument of [“A”, “B”, “Z”], we would have the following
console.log(object); // returns{“A”: 0,“B”: 0,“Z”: 0}
  • Next we use a for-loop inside of another for-loop, pretty grainy, I know so that we can assign the number values we need that pertain to the amount of books we have for each category
  • We iterate over the length of the listOfArt argument’s length until our special counter x is less than-or-equal-to listOfArt’s length — 1. Each time we finish a pass of the code block we increase x by 1.
  • Inside that for-loop, we iterate over the length of our object variable being turned into an array (at run time, not in any permanent way) minus 1, and each time we complete the code block we increment this for-loop’s special counter, k, by 1
  • If the first character of the whatever value x indicates the index of for listOfArt is equal to the particular key of object that we are focusing on at that moment inside the inner for loop…

(if yes)

  • then we create a variable called letter and in that moment it will equal the key of object
  • we also create a variable called value that seeks an integer, via parseInt being used on the creating of an array out of the value of whatever index x stands for in listOfArt, with the temporary array being separated by the space that is between the long letter code and the number of books that we want.
  • we refer to that number of books with the [1] index value
  • Then we say that the value for the object key that is equal to letter is equal to the variable we created and gave a value to called value
for(let x=0; x<=listOfArt.length — 1; x++){   for(let k = 0; k < Object.keys(object).length; k++){      if(listOfArt[x][0] == Object.keys(object)[k]){      let letter = Object.keys(object)[k];      let value = parseInt(listOfArt[x].split(‘ ‘)[1]);      object[letter] += value;      }   }}
You don’t hate me, I hate me. #alwaysmad
//assume thatlistOfArt = [“ABAR 200”, “CDXE 500”, “BKWR 250”, “BTSQ 890”, “DRTY 600”]listOfCat = [“A”, “B”]console.log(object) //{A: 200,B: 1140}
(CategoryLetter : Number)*space*-*space*
(CategoryLetter : Number)
‘(A : 0) — (B : 1290) — (C : 515) — (D : 600)’
  • place the name in our string: the first value of the temporary array element being made by our use of the Object-method .entries( ) *which takes our object variable as an argument*
  • place the regular text parts in our string
  • place the the value that is currently the second value in our temporary array made by the aforementioned means
answer += `(${Object.entries(object)[z][0]} : ${Object.entries(object)[z][1]}) — `;
answer += `(${Object.entries(object)[z][0]} : ${Object.entries(object)[z][1]})`
if(listOfArt[0] == undefined){answer = ‘’;}
function stockList(listOfArt, listOfCat){let answer = ‘’;let object = {};   for (var i=0; i < listOfCat.length; i++) {      object[listOfCat[i]] = 0;   };   for(let x=0; x<=listOfArt.length — 1; x++){      for(let k = 0; k < Object.keys(object).length; k++){         if(listOfArt[x][0] == Object.keys(object)[k]){              let letter = Object.keys(object)[k];              let value = parseInt(listOfArt[x].split(‘ ‘)[1]);              object[letter] += value;          }     }   }   for(let z = 0; z <= Object.entries(object).length — 1; z ++ ){     if(z !== Object.entries(object).length — 1){
answer += `(${Object.entries(object)[z][0]} : ${Object.entries(object)[z][1]}) — `;
} else {
answer += `(${Object.entries(object)[z][0]} : ${Object.entries(object)[z][1]})`
} } if(listOfArt[0] == undefined){ answer = ‘’; }return answer;}
function stockList(listOfArt, listOfCat) {var qs = {};if (!listOfArt.length) return ‘’;   listOfArt.forEach(function(art) {      var cat = art[0];      qs[cat] = (qs[cat] | 0) + +art.split(‘ ‘)[1];   });   return listOfCat.map(function(c) {      return ‘(‘ + c + ‘ : ‘ + (qs[c] | 0) + ‘)’;      }).join(‘ — ‘);   }
}
var cat = art[0];
You’re a CodeVenger now, keep up? #lol #onedayatatime
listOfArt.forEach(function(art) {   var cat = art[0];   qs[cat] = (qs[cat] | 0) + +art.split(‘ ‘)[1];});
{ A: 200, C: 500, B: 1140, D: 600 }
return listOfCat.map(function(c) {   return ‘(‘ + c + ‘ : ‘ + (qs[c] | 0) + ‘)’;}).join(‘ — ‘);
If we were rappers, these guys were Biggie and I was Silkk the Shocker.
Tenochtitlan (& Wakanda) FOREVER!!!

Task

Rules

Example

wave("hello") => ["Hello", "hEllo", "heLlo", "helLo", "hellO"]

How it’s done:

function wave(str){   let result = [];   str.split(“”).forEach((char, index) => {      if (/[a-z]/.test(char)) {      result.push(str.slice(0, index) + char.toUpperCase() +       str.slice(index + 1));      }   });return result;}
  • We create the variable result to hold our answer. It’s an empty array.
  • We use the string-method .split(“”) on our string to turn it into an array. Then we chain on .forEach( ) & pass in arguments to take the place of the current value char and the current value’s index index.
  • In the for loop implied by the use of .forEach( ) we use a RegEx expression to seek a letter and test if the value being iterated upon char matches any of those lowercase values
  • If they do, then we push a string into our results array
  • The string is constructed as follows:
  • We use the .slice( ) string-method to return a new string from an existing string, in our case we have three string chunks
  1. The portion of the string that is from the start to where our index from the .forEach( ) loop’s callback’s argument indicates
  2. The one character in the string that we want to be uppercase, referred to from the use of the .forEach( ) method as char (forEach’s argument referring to the value being iterated on) and then chained onto with toUpperCase( ), a string method that turns strings into…well…uppercase.
  3. The rest of the string that starts from whatever value index means plus 1 added to that, so that we get the rest of the string after where we stopped to use .upperCase( ).

--

--

--

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

Financial Planning and Banking Applications: Why Testing is a Key?

Q&A with Jeffrey Wan on Turing School, Flatiron School, and coding bootcamps — reasons people fail…

An Introduction to Cloud Storage

Stopping Time in Java Unit Tests

Terraria

Alvin’s Dew Drop Daily — Issue #105

Unit Testing Best Practices In .NET C#

Tips, tricks and best practices of Unit Testing in DotNet (.NET) CSharp (C#) using NUnit and Moq. Coding Code Programming Software Engineering Architecture Development Coverage Mock Stub Abstract Dependency Injection (DI) Test Driven Development (TDD)

Whenever we switch security awareness training vendors, it seems like an unspoken challenge among…

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

BEST SOFTWARE DEVELOPMENT

Refactoring in Software Development

Getting it with Git

Secure Software Development Lifecycle