-
Notifications
You must be signed in to change notification settings - Fork 0
/
workshop.js
94 lines (42 loc) · 19.4 KB
/
workshop.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
///// Workshop on arrays and objects
// The next few lines have a big string bound to a variable for you to work with. Don't change this string, just scroll past it!
const middlemarchChapter2 = 'CHAPTER II. “‘Dime; no ves aquel caballero que hacia nosotros viene sobre un caballo rucio rodado que trae puesto en la cabeza un yelmo de oro?’ ‘Lo que veo y columbro,’ respondio Sancho, ‘no es sino un hombre sobre un as no pardo como el mio, que trae sobre la cabeza una cosa que relumbra.’ ‘Pues ese es el yelmo de Mambrino,’ dijo Don Quijote.”—CERVANTES. “‘Seest thou not yon cavalier who cometh toward us on a dapple-gray steed, and weareth a golden helmet?’ ‘What I see,’ answered Sancho, ‘is nothing but a man on a gray ass like my own, who carries something shiny on his head.’ ‘Just so,’ answered Don Quixote: ‘and that resplendent object is the helmet of Mambrino.’” “Sir Humphry Davy?” said Mr. Brooke, over the soup, in his easy smiling way, taking up Sir James Chettam’s remark that he was studying Davy’s Agricultural Chemistry. “Well, now, Sir Humphry Davy; I dined with him years ago at Cartwright’s, and Wordsworth was there too—the poet Wordsworth, you know. Now there was something singular. I was at Cambridge when Wordsworth was there, and I never met him—and I dined with him twenty years afterwards at Cartwright’s. There’s an oddity in things, now. But Davy was there: he was a poet too. Or, as I may say, Wordsworth was poet one, and Davy was poet two. That was true in every sense, you know.” Dorothea felt a little more uneasy than usual. In the beginning of dinner, the party being small and the room still, these motes from the mass of a magistrate’s mind fell too noticeably. She wondered how a man like Mr. Casaubon would support such triviality. His manners, she thought, were very dignified; the set of his iron-gray hair and his deep eye-sockets made him resemble the portrait of Locke. He had the spare form and the pale complexion which became a student; as different as possible from the blooming Englishman of the red-whiskered type represented by Sir James Chettam. “I am reading the Agricultural Chemistry,” said this excellent baronet, “because I am going to take one of the farms into my own hands, and see if something cannot be done in setting a good pattern of farming among my tenants. Do you approve of that, Miss Brooke?” “A great mistake, Chettam,” interposed Mr. Brooke, “going into electrifying your land and that kind of thing, and making a parlor of your cow-house. It won’t do. I went into science a great deal myself at one time; but I saw it would not do. It leads to everything; you can let nothing alone. No, no—see that your tenants don’t sell their straw, and that kind of thing; and give them draining-tiles, you know. But your fancy farming will not do—the most expensive sort of whistle you can buy: you may as well keep a pack of hounds.” “Surely,” said Dorothea, “it is better to spend money in finding out how men can make the most of the land which supports them all, than in keeping dogs and horses only to gallop over it. It is not a sin to make yourself poor in performing experiments for the good of all.” She spoke with more energy than is expected of so young a lady, but Sir James had appealed to her. He was accustomed to do so, and she had often thought that she could urge him to many good actions when he was her brother-in-law. Mr. Casaubon turned his eyes very markedly on Dorothea while she was speaking, and seemed to observe her newly. “Young ladies don’t understand political economy, you know,” said Mr. Brooke, smiling towards Mr. Casaubon. “I remember when we were all reading Adam Smith. _There_ is a book, now. I took in all the new ideas at one time—human perfectibility, now. But some say, history moves in circles; and that may be very well argued; I have argued it myself. The fact is, human reason may carry you a little too far—over the hedge, in fact. It carried me a good way at one time; but I saw it would not do. I pulled up; I pulled up in time. But not too hard. I have always been in favor of a little theory: we must have Thought; else we shall be landed back in the dark ages. But talking of books, there is Southey’s ‘Peninsular War.’ I am reading that of a morning. You know Southey?” “No,” said Mr. Casaubon, not keeping pace with Mr. Brooke’s impetuous reason, and thinking of the book only. “I have little leisure for such literature just now. I have been using up my eyesight on old characters lately; the fact is, I want a reader for my evenings; but I am fastidious in voices, and I cannot endure listening to an imperfect reader. It is a misfortune, in some senses: I feed too much on the inward sources; I live too much with the dead. My mind is something like the ghost of an ancient, wandering about the world and trying mentally to construct it as it used to be, in spite of ruin and confusing changes. But I find it necessary to use the utmost caution about my eyesight.” This was the first time that Mr. Casaubon had spoken at any length. He delivered himself with precision, as if he had been called upon to make a public statement; and the balanced sing-song neatness of his speech, occasionally corresponded to by a movement of his head, was the more conspicuous from its contrast with good Mr. Brooke’s scrappy slovenliness. Dorothea said to herself that Mr. Casaubon was the most interesting man she had ever seen, not excepting even Monsieur Liret, the Vaudois clergyman who had given conferences on the history of the Waldenses. To reconstruct a past world, doubtless with a view to the highest purposes of truth—what a work to be in any way present at, to assist in, though only as a lamp-holder! This elevating thought lifted her above her annoyance at being twitted with her ignorance of political economy, that never-explained science which was thrust as an extinguisher over all her lights. “But you are fond of riding, Miss Brooke,” Sir James presently took an opportunity of saying. “I should have thought you would enter a little into the pleasures of hunting. I wish you would let me send over a chestnut horse for you to try. It has been trained for a lady. I saw you on Saturday cantering over the hill on a nag not worthy of you. My groom shall bring Corydon for you every day, if you will only mention the time.” “Thank you, you are very good. I mean to give up riding. I shall not ride any more,” said Dorothea, urged to this brusque resolution by a little annoyance that Sir James would be soliciting her attention when she wanted to give it all to Mr. Casaubon. “No, that is too hard,” said Sir James, in a tone of reproach that showed strong interest. “Your sister is given to self-mortification, is she not?” he continued, turning to Celia, who sat at his right hand. “I think she is,” said Celia, feeling afraid lest she should say something that would not please her sister, and blushing as prettily as possible above her necklace. “She likes giving up.” “If that were true, Celia, my giving-up would be self-indulgence, not self-mortification. But there may be good reasons for choosing not to do what is very agreeable,” said Dorothea. Mr. Brooke was speaking at the same time, but it was evident that Mr. Casaubon was observing Dorothea, and she was aware of it. “Exactly,” said Sir James. “You give up from some high, generous motive.” “No, indeed, not exactly. I did not say that of myself,” answered Dorothea, reddening. Unlike Celia, she rarely blushed, and only from high delight or anger. At this moment she felt angry with the perverse Sir James. Why did he not pay attention to Celia, and leave her to listen to Mr. Casaubon?—if that learned man would only talk, instead of allowing himself to be talked to by Mr. Brooke, who was just then informing him that the Reformation either meant something or it did not, that he himself was a Protestant to the core, but that Catholicism was a fact; and as to refusing an acre of your ground for a Romanist chapel, all men needed the bridle of religion, which, properly speaking, was the dread of a Hereafter. “I made a great study of theology at one time,” said Mr. Brooke, as if to explain the insight just manifested. “I know something of all schools. I knew Wilberforce in his best days. Do you know Wilberforce?” Mr. Casaubon said, “No.” “Well, Wilberforce was perhaps not enough of a thinker; but if I went into Parliament, as I have been asked to do, I should sit on the independent bench, as Wilberforce did, and work at philanthropy.” Mr. Casaubon bowed, and observed that it was a wide field. “Yes,” said Mr. Brooke, with an easy smile, “but I have documents. I began a long while ago to collect documents. They want arranging, but when a question has struck me, I have written to somebody and got an answer. I have documents at my back. But now, how do you arrange your documents?” “In pigeon-holes partly,” said Mr. Casaubon, with rather a startled air of effort. “Ah, pigeon-holes will not do. I have tried pigeon-holes, but everything gets mixed in pigeon-holes: I never know whether a paper is in A or Z.” “I wish you would let me sort your papers for you, uncle,” said Dorothea. “I would letter them all, and then make a list of subjects under each letter.” Mr. Casaubon gravely smiled approval, and said to Mr. Brooke, “You have an excellent secretary at hand, you perceive.” “No, no,” said Mr. Brooke, shaking his head; “I cannot let young ladies meddle with my documents. Young ladies are too flighty.” Dorothea felt hurt. Mr. Casaubon would think that her uncle had some special reason for delivering this opinion, whereas the remark lay in his mind as lightly as the broken wing of an insect among all the other fragments there, and a chance current had sent it alighting on _her_. When the two girls were in the drawing-room alone, Celia said— “How very ugly Mr. Casaubon is!” “Celia! He is one of the most distinguished-looking men I ever saw. He is remarkably like the portrait of Locke. He has the same deep eye-sockets.” “Had Locke those two white moles with hairs on them?” “Oh, I dare say! when people of a certain sort looked at him,” said Dorothea, walking away a little. “Mr. Casaubon is so sallow.” “All the better. I suppose you admire a man with the complexion of a _cochon de lait_.” “Dodo!” exclaimed Celia, looking after her in surprise. “I never heard you make such a comparison before.” “Why should I make it before the occasion came? It is a good comparison: the match is perfect.” Miss Brooke was clearly forgetting herself, and Celia thought so. “I wonder you show temper, Dorothea.” “It is so painful in you, Celia, that you will look at human beings as if they were merely animals with a toilet, and never see the great soul in a man’s face.” “Has Mr. Casaubon a great soul?” Celia was not without a touch of naive malice. “Yes, I believe he has,” said Dorothea, with the full voice of decision. “Everything I see in him corresponds to his pamphlet on Biblical Cosmology.” “He talks very little,” said Celia “There is no one for him to talk to.” Celia thought privately, “Dorothea quite despises Sir James Chettam; I believe she would not accept him.” Celia felt that this was a pity. She had never been deceived as to the object of the baronet’s interest. Sometimes, indeed, she had reflected that Dodo would perhaps not make a husband happy who had not her way of looking at things; and stifled in the depths of her heart was the feeling that her sister was too religious for family comfort. Notions and scruples were like spilt needles, making one afraid of treading, or sitting down, or even eating. When Miss Brooke was at the tea-table, Sir James came to sit down by her, not having felt her mode of answering him at all offensive. Why should he? He thought it probable that Miss Brooke liked him, and manners must be very marked indeed before they cease to be interpreted by preconceptions either confident or distrustful. She was thoroughly charming to him, but of course he theorized a little about his attachment. He was made of excellent human dough, and had the rare merit of knowing that his talents, even if let loose, would not set the smallest stream in the county on fire: hence he liked the prospect of a wife to whom he could say, “What shall we do?” about this or that; who could help her husband out with reasons, and would also have the property qualification for doing so. As to the excessive religiousness alleged against Miss Brooke, he had a very indefinite notion of what it consisted in, and thought that it would die out with marriage. In short, he felt himself to be in love in the right place, and was ready to endure a great deal of predominance, which, after all, a man could always put down when he liked. Sir James had no idea that he should ever like to put down the predominance of this handsome girl, in whose cleverness he delighted. Why not? A man’s mind—what there is of it—has always the advantage of being masculine,—as the smallest birch-tree is of a higher kind than the most soaring palm,—and even his ignorance is of a sounder quality. Sir James might not have originated this estimate; but a kind Providence furnishes the limpest personality with a little gum or starch in the form of tradition. “Let me hope that you will rescind that resolution about the horse, Miss Brooke,” said the persevering admirer. “I assure you, riding is the most healthy of exercises.” “I am aware of it,” said Dorothea, coldly. “I think it would do Celia good—if she would take to it.” “But you are such a perfect horsewoman.” “Excuse me; I have had very little practice, and I should be easily thrown.” “Then that is a reason for more practice. Every lady ought to be a perfect horsewoman, that she may accompany her husband.” “You see how widely we differ, Sir James. I have made up my mind that I ought not to be a perfect horsewoman, and so I should never correspond to your pattern of a lady.” Dorothea looked straight before her, and spoke with cold brusquerie, very much with the air of a handsome boy, in amusing contrast with the solicitous amiability of her admirer. “I should like to know your reasons for this cruel resolution. It is not possible that you should think horsemanship wrong.” “It is quite possible that I should think it wrong for me.” “Oh, why?” said Sir James, in a tender tone of remonstrance. Mr. Casaubon had come up to the table, teacup in hand, and was listening. “We must not inquire too curiously into motives,” he interposed, in his measured way. “Miss Brooke knows that they are apt to become feeble in the utterance: the aroma is mixed with the grosser air. We must keep the germinating grain away from the light.” Dorothea colored with pleasure, and looked up gratefully to the speaker. Here was a man who could understand the higher inward life, and with whom there could be some spiritual communion; nay, who could illuminate principle with the widest knowledge: a man whose learning almost amounted to a proof of whatever he believed! Dorothea’s inferences may seem large; but really life could never have gone on at any period but for this liberal allowance of conclusions, which has facilitated marriage under the difficulties of civilization. Has any one ever pinched into its pilulous smallness the cobweb of pre-matrimonial acquaintanceship? “Certainly,” said good Sir James. “Miss Brooke shall not be urged to tell reasons she would rather be silent upon. I am sure her reasons would do her honor.” He was not in the least jealous of the interest with which Dorothea had looked up at Mr. Casaubon: it never occurred to him that a girl to whom he was meditating an offer of marriage could care for a dried bookworm towards fifty, except, indeed, in a religious sort of way, as for a clergyman of some distinction. However, since Miss Brooke had become engaged in a conversation with Mr. Casaubon about the Vaudois clergy, Sir James betook himself to Celia, and talked to her about her sister; spoke of a house in town, and asked whether Miss Brooke disliked London. Away from her sister, Celia talked quite easily, and Sir James said to himself that the second Miss Brooke was certainly very agreeable as well as pretty, though not, as some people pretended, more clever and sensible than the elder sister. He felt that he had chosen the one who was in all respects the superior; and a man naturally likes to look forward to having the best. He would be the very Mawworm of bachelors who pretended not to expect it.'
///// 1. Define a function named countChars that takes a string as an argument and returns a number representing how many characters are in the string.
// Start of your code
// End of your code
console.log(countChars(middlemarchChapter2));
///// 2. Define a function named countWords that takes a string as an argument and returns a number representing how many words are in the string.
// Start of your code
// End of your code
console.log(countWords(middlemarchChapter2));
///// 3. Define a function named getWordsByLength that takes two arguments, a string and a number, and returns an array containing all the words in the string that have the exact number of characters specified by the number. Duplicating words is OK. Including punctuation is OK.
// Start of your code
// End of your code
console.log(getWordsByLength(middlemarchChapter2, 11).slice(0, 10));
///// 4. Define a function named getCapitalLetters that takes a string as an argument and returns a string with just the capital letters from the original string.
// Start of your code
// End of your code
console.log(getCapitalLetters(middlemarchChapter2));
///// 5. Define a function named wordCounts that takes a string as an argument and returns an object containing each word that appears in the string, as well as the number of times it appears.
// Start of your code
// End of your code
console.log(wordCounts(middlemarchChapter2).get('they'));
///// 6. Refine your wordCounts function above to normalize the data before adding it to the object. All the words should be lowercase, free of whitespace, and free of all punctuation except hyphens (-).
console.log(wordCounts(middlemarchChapter2).get('fifty'));
///// 7. Define a class named Song that creates objects resembling digital recordings. The constructor should take two arguments, a song name and the number of times a song has been played. Any songs created using the class should each have a name and a numberOfPlays to track how many times the song has been played. They should also have a play() method that logs the music emoji to the console (🎵) and increases the numberOfPlays by 1.
// Start of your code
// End of your code
let testSong = new Song('Yellow Submarine', 0);
testSong.play();
testSong.play();
console.log(testSong.name, testSong.numberOfPlays);
///// 8. Define a function called makeSongs that takes a string as an argument and returns an array of Song objects. There should be one song for each word in the string, and the number of plays should be set to the number of times the word appears in the string.
// Start of your code
// End of your code
let songs = makeSongs(middlemarchChapter2);
for (let i = 0; i < 200; i+=20) {
console.log(songs[i].name, songs[i].numberOfPlays);
songs[i].play();
console.log(songs[i].name, songs[i].numberOfPlays);
console.log('\n');
}