Day 18 of 100 Days Of Code

Day 18: August 11, Saturday

Today ‘s Progress: I started work Intermediate Algorithm Scripting.

Thoughts: These algorithm challenges are just as hard as the other algorithm challenge I took the approach of visualizing the requirements and array sets then walking though the JS steps. For example:

console.log("Seek and Destroy");
//You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments. Note: You have to use the arguments object.
function destroyer(arr, a1, a2) {
  // Remove all the values
  console.log("Initial Array -->  " + arguments[0]);//Array argument 0  
  var args = Array.from(arguments).slice(1);
  console.log("Filter argument -->  " + (args = Array.from(arguments).slice(1)));//eval arguments
    return arr.filter(function(val) {
      return !args.includes(val);
    });
  return arr;
}
console.log(destroyer([1, 2, 3, 1, 2, 3], 2, 3)); //should return [1, 1].
console.log(destroyer([1, 2, 3, 5, 1, 2, 3], 2, 3)); //should return [1, 5, 1].
console.log(destroyer([3, 5, 1, 2, 2], 2, 3, 5)); //should return [1].
console.log(destroyer([2, 3, 2, 3], 2, 3)); //should return [].
console.log(destroyer(["tree", "hamburger", 53], "tree", 53)); //should return ["hamburger"].
console.log(destroyer(["possum", "trollo", 12, "safari", "hotdog", 92, 65, "grandma", "bugati", "trojan", "yacht"], "yacht", "possum", "trollo", "safari", "hotdog", "grandma", "bugati", "trojan")); //should return [12,92,65].
console.log("<----------------------next exercise------------------------->");

This one took some google searching and trying to figure out how to get Array.from(arguments).slice to work in my solution… Arguments object

Link(s) to work

  1. Started Intermediate Algorithm Scripting.

Introduction to the Functional Programming Challenges

  • PassedSum All Numbers in a Range
  • PassedDiff Two Arrays
  • PassedSeek and Destroy

All code is in GitHub and repl.it here: repl.it IntermediateAlgorithmScripting.js or GitHub IntermediateAlgorithmScripting.js

Written on August 11, 2018