Not much happening today. I did laundry yesterday so that is out of the way. Coding was a bit hard today. Lots of googling and getting hints on how to solve the problem. And laundry needed to be done since I’m packing on Thursday (we are leaving Friday to go to Lexi’s school) and I’d like to have all the clothes washed. It was chores today for the youngins. And no one complained about it.
I’m finishing up “Tomorrow and tomorrow and tomorrow,” It started out well and then it became annoying that I’m having a hard time finishing it up. The story is essentially about gamers and video games, throwing up constant references to the history of gaming and gaming culture. (Which I love) The two main characters, Sadie and Sam, bond over playing video games when the pair meet in the children’s ward of a hospital and later program games of their own. Both characters are rather insufferable, immature, and showed no growth. For a book supposedly celebrating friendship, this was the definition of a toxic, unhealthy platonic relationship between male & female. So I’m not quite sure what this story is supposed to be about. It’s certainly not about friendship.
And I still haven’t finished Dracula. /sigh ..I will eventually.
I’m going to exercise early again today. The other night I exercised after I made dinner and ended up eating dinner at 9:30. By the time I could eat, all the food was being put away. I was running into the kitchen yelling, “Stop! I haven’t eaten yet!” Normally Krissy will go around and ask everyone if they want more or ask if everyone ate. I think cause it was so late that she assumed I had already eaten. Given that I made dinner and usually serve myself before leaving the kitchen.
Merlin and Mimi are behaving themselves today. Merlin actually waited until Mimi was done eating lunch before pouncing and playing.
That’s it for today. Tomorrow will be a bit busier with packing and getting my flu shot. And I have therapy also.
JavaScript notes…
———————————-
The sort method sorts the elements of an array according to the callback function.
For example:
function ascendingOrder(arr) { return arr.sort(function(a, b) { return a - b; }); } ascendingOrder([1, 5, 2, 3, 4]);
This would return the value [1, 2, 3, 4, 5].
function reverseAlpha(arr) { return arr.sort(function(a, b) { return a === b ? 0 : a < b ? 1 : -1; }); } reverseAlpha(['l', 'h', 'z', 'b', 's']);
This would return the value ['z', 's', 'l', 'h', 'b'].
JavaScript's default sorting method is by string Unicode point value, which may return unexpected results. Therefore, it is encouraged to provide a callback function to specify how to sort the array items. When such a callback function, normally called compareFunction, is supplied, the array elements are sorted according to the return value of the compareFunction: If compareFunction(a,b) returns a value less than 0 for two elements a and b, then a will come before b. If compareFunction(a,b) returns a value greater than 0 for two elements a and b, then b will come before a. If compareFunction(a,b) returns a value equal to 0 for two elements a and b, then a and b will remain unchanged.
Use the sort method in the alphabeticalOrder function to sort the elements of arr in alphabetical order. The function should return the sorted array.
function alphabeticalOrder(arr) { // Only change code below this line return arr // Only change code above this line } alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
return arr.sort(function(a, b) { return a === b ? 0 : a > b ? 1 : -1; });
A side effect of the sort method is that it changes the order of the elements in the original array. In other words, it mutates the array in place. One way to avoid this is to first concatenate an empty array to the one being sorted (remember that slice and concat return a new array), then run the sort method.
Use the sort method in the nonMutatingSort function to sort the elements of an array in ascending order. The function should return a new array, and not mutate the globalArray variable.
const globalArray = [5, 6, 3, 2, 9]; function nonMutatingSort(arr) { // Only change code below this line // Only change code above this line } nonMutatingSort(globalArray);
var globalArray = [5, 6, 3, 2, 9]; function nonMutatingSort(arr) { // Add your code below this line return [].concat(arr).sort(function(a, b) { return a - b; }); // Add your code above this line } nonMutatingSort(globalArray);
The split method splits a string into an array of strings. It takes an argument for the delimiter, which can be a character to use to break up the string or a regular expression. For example, if the delimiter is a space, you get an array of words, and if the delimiter is an empty string, you get an array of each character in the string.
Here are two examples that split one string by spaces, then another by digits using a regular expression:
const str = "Hello World"; const bySpace = str.split(" "); const otherString = "How9are7you2today"; const byDigits = otherString.split(/\d/);
bySpace would have the value ["Hello", "World"] and byDigits would have the value ["How", "are", "you", "today"].
Since strings are immutable, the split method makes it easier to work with them.
Use the split method inside the splitify function to split str into an array of words. The function should return the array. Note that the words are not always separated by spaces, and the array should not contain punctuation.
function splitify(str) { // Only change code below this line // Only change code above this line } splitify("Hello World,I-am code");
function splitify(str) { // Only change code below this line return str.split(/\W/); // Only change code above this line } splitify("Hello World,I-am code");
The join method is used to join the elements of an array together to create a string. It takes an argument for the delimiter that is used to separate the array elements in the string.
Here's an example:
const arr = ["Hello", "World"]; const str = arr.join(" ");
str would have a value of the string Hello World.
Use the join method (among others) inside the sentensify function to make a sentence from the words in the string str. The function should return a string. For example, I-like-Star-Wars would be converted to I like Star Wars. For this challenge, do not use the replace method.
function sentensify(str) { // Only change code below this line // Only change code above this line } sentensify("May-the-force-be-with-you");
function sentensify(str) { // Only change code below this line return str.split(/\W/).join(" "); // Only change code above this line } sentensify("May-the-force-be-with-you")
The last several challenges covered a number of useful array and string methods that follow functional programming principles. We've also learned about reduce, which is a powerful method used to reduce problems to simpler forms. From computing averages to sorting, any array operation can be achieved by applying it. Recall that map and filter are special cases of reduce.
Let's combine what we've learned to solve a practical problem.
Many content management sites (CMS) have the titles of a post added to part of the URL for simple bookmarking purposes. For example, if you write a Medium post titled Stop Using Reduce, it's likely the URL would have some form of the title string in it (.../stop-using-reduce). You may have already noticed this on the freeCodeCamp site.
Fill in the urlSlug function so it converts a string title and returns the hyphenated version for the URL. You can use any of the methods covered in this section, and don't use replace. Here are the requirements:
The input is a string with spaces and title-cased words
The output is a string with the spaces between words replaced by a hyphen (-)
The output should be all lower-cased letters
The output should not have any spaces
// Only change code below this line function urlSlug(title) { } // Only change code above this line urlSlug("A Mind Needs Books Like A Sword Needs A Whetstone");
// Only change code below this line function urlSlug(title) { let titleCopy = title.slice().toLowerCase().split(" "); let filteredWords = titleCopy.filter(function(word) { if(word != "") { return word; } }); return filteredWords.join("-"); } // Only change code above this line urlSlug("A Mind Needs Books Like A Sword Needs A Whetstone");