-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes.js
1229 lines (909 loc) · 23.9 KB
/
notes.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
npm install --save bootstrap@3
npm install -g @angular/cli
ng serve --open
js = just in time compiled
======================================
var Car = function() {
this.wheels = 4;
this.engines = 1;
this.seats = 5;
};
// Only change code below this line.
var myCar = function(){
this.wheels = 4;
this.engines = 1;
this.seats = 5;
this.turboType = "twin";
};
myCar.nickname = 'Ford';
===================
1 - answer = "alpha"
2 - answer = "beta"
3 - answer = "gamma"
4 - answer = "delta"
switch (val) {
case 1:
answer = "alpha";
break;
case 2:
answer = "beta";
break;
case 3:
answer = "gamma";
break;
case 4:
answer = "delta";
break;
}
switch (val) {
case 1:
case 2:
case 3:
answer = "Low";
break;
case 4:
case 5:
case 6:
answer = "Mid";
break;
case 7:
case 8:
case 4:
answer = "High";
}
1-3 - "Low"
4-6 - "Mid"
7-9 - "High"
===========
if (val === "bob") {
answer = "Marley";
} else if (val === 42) {
answer = "The Answer";
} else if (val === 1) {
answer = "There is no #1";
} else if (val === 99) {
answer = "Missed me by this much!";
} else if (val === 7) {
answer = "Ate Nine";
}
switch (val) {
case "bob":
answer = "Marley";
brake;
case 42:
answer = "The Answer";
brake;
case 1:
answer = "There is no #1";
brake;
case 99:
answer = "Missed me by this much!";
brake;
case 7:
answer = "Ate Nine";
}
======== q 106 ============
+1 2, 3, 4, 5, 6
0 7, 8, 9
-1 10, 'J', 'Q', 'K', 'A'
switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
count++;
break;
case 7:
case 8:
case 9:
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count--;
}
if (count > 0) return count + " Bet";
return count + " Hold";
================================
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<style>
h2 {
font-family: Lobster, Monospace;
}
.thick-green-border {
border-color: green;
border-width: 10px;
border-style: solid;
border-radius: 50%;
}
</style>
<div class="container-fluid">
<h2 class="text-primary text-center">CatPhotoApp</h2>
<a href="#"><img class="img-responsive thick-green-border" src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back. "></a>
<img src="https://bit.ly/fcc-running-cats" class="img-responsive" alt="Three kittens running towards the camera. ">
<div class="row">
<div class="col-xs-4">
<button class="btn btn-block btn-primary">Like</button>
</div>
<div class="col-xs-4">
<button class="btn btn-block btn-info">Info</button>
</div>
<div class="col-xs-4">
<button class="btn btn-block btn-danger">Delete</button>
</div>
</div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
<form action="/submit-cat-photo">
<label><input type="radio" name="indoor-outdoor"> Indoor</label>
<label><input type="radio" name="indoor-outdoor"> Outdoor</label>
<label><input type="checkbox" name="personality"> Loving</label>
<label><input type="checkbox" name="personality"> Lazy</label>
<label><input type="checkbox" name="personality"> Crazy</label>
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
</div>
=====================
$("button").addClass('animated');
$(".btn").addClass('shake');
$("#target1").addClass('btn-primary');
$("#target1").css("color", "blue");
<script>
$(document).ready(function() {
$("button").addClass("animated bounce");
$(".well").addClass("animated shake");
$("#target3").addClass("animated fadeOut");
$("button").removeClass("btn-default");
});
</script>
$("#target1").prop("disabled", true);
<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
$("#target1").remove();
$("#target2").appendTo("#right-well");
$("#target2").clone().appendTo("#right-well");
$("#target1").parent().css("background-color", "red")
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
$("#target4").remove();
$("#target2").appendTo("#right-well");
$("#target5").clone().appendTo("#left-well");
$("#target1").parent().css("background-color", "red")
$("#right-well").children().css("color", "orange")
$(".target:nth-child(3)").addClass("animated bounce");
});
</script>
var gloveBoxContents = ourStorage.car.inside["glove box"]; // Change this line
// Example
var ourArray = [];
for (var i = 10; i > 0; i -= 2) {
ourArray.push(i);
}
// Setup
var myArray = [];
// Only change code below this line.
for (var i = 9; i > 0; i -= 2) {
myArray.push(i);
}
//Setup
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
}
];
// profile-lookup
//Setup
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
}
];
function lookUpProfile(firstName, prop){
// Only change code below this line
var output = "";
var propFound = false;
for (var i = 0; i < contacts.length; i++) {
if(contacts[i].firstName == firstName){
output = contacts[i].firstName;
if (contacts[i].hasOwnProperty(prop)){
//if (contacts[i].prop != ""){
// do
propFound = true;
return contacts[i][prop];
}
}
}
if (propFound == true && output != ''){
return output;
}
if (output == ''){
return "No such contact";
}
if (propFound == false){
return "No such property";
}
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Akira", "likes");
===============
Math.floor(Math.random() * 20);
============================
// Setup
var testString = "Ada Lovelace and Charles Babbage designed the first computer and the software that would have run on it.";
// Example
var expressionToGetSoftware = /software/gi;
var softwareCount = testString.match(expressionToGetSoftware).length;
// Only change code below this line.
var expression = /and/gi; // Change this Line
// Only change code above this line
// This code counts the matches of expression in testString
var andCount = testString.match(expression).length;
var expression = /\d+/g; // for digits
\s to find whitespace in a string.
The whitespace characters are " " (space), \r (the carriage return), \n (newline), \t (tab), and \f (the form feed).
===========================
var Car = function(wheels, seats, engines) {
this.wheels = wheels;
this.seats = seats;
this.engines = engines;
};
var myCar = new Car(6, 3, 1);
{
wheels: 6,
seats: 3,
engines: 1
}
==============================
var Car = function() {
// this is a private variable
var speed = 10;
// these are public methods
this.accelerate = function(change) {
speed += change;
};
this.decelerate = function() {
speed -= 5;
};
this.getSpeed = function() {
return speed;
};
};
var Bike = function() {
// Only change code below this line.
var gear;
this.getGear = function() {
return gear;
};
this.setGear = function(change) {
gear = change;
};
};
var myCar = new Car();
var myBike = new Bike();
=========================
var oldArray = [1,2,3,4,5];
// Only change code below this line.
var newArray = oldArray.map(function(val){
return val + 3;
});
================
// GET TOTAL OF ALL ITEMS IN ARRAY
var array = [4,5,6,7,8];
var singleVal = 0;
// Only change code below this line.
singleVal = array.reduce(function(previousVal, currentVal) {
return previousVal += currentVal;
}, 0);
// Filter array
var oldArray = [1,2,3,4,5,6,7,8,9,10];
// Only change code below this line.
var newArray = oldArray.filter(function(val) {
return val < 6;
});
///////// sorting from largest to smallest
var array = [1, 12, 21, 2];
// Only change code below this line.
array.sort(function(a, b) {
return b - a;
});
=================== reverse array
function reverseString(str) {
var array1 = str.split('');
var reversed = array1.reverse();
str = reversed.join("");
return str;
}
reverseString("hello");
// factorial
function factorialize(num) {
var j = 1;
for (var i = 1; i <= num; i++) {
j*= i;
}
return j;
}
factorialize(5);
///////////// split array; source = https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
var animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];
console.log(animals.slice(2));
// expected output: Array ["camel", "duck", "elephant"]
console.log(animals.slice(2, 4));
// expected output: Array ["camel", "duck"]
console.log(animals.slice(0, 3));
// expected output: Array ["bison", "camel", "duck", "elephant"]
================
reg exp:
i
function palindrome(str) {
var newStr = str.toLowerCase();
var newstr = newStr.replace(/\W\d*\s*\_*\,*\**\#/gi, '');
var count = Math.floor(newstr.length/2);
console.log(count);
var array1 = newstr.split('');
var half1 = array1.slice(0, count);
var half2 = array1.slice(count+1);
var reversed = half2.reverse();
var str2 = reversed.join("");
var str1 = half1.join("");
if (str1 == str2){
return true;
}
return false;
}
palindrome("eye");
// palindrdome solution
function palindrome(str) {
var newstr = str.toLowerCase().replace(/[^a-z0-9]/gi, '');
var reversed = newstr.split('').reverse().join("");
//document.getElementById("demo2").innerHTML = reversed;
return (newstr == reversed);
}
palindrome("eye");
var max_of_array = Math.max.apply(Math, array);
// longer word solution
function findLongestWord(str) {
var words = str.split(' ');
var wordLenghts = words.map(function(val){
return val.length;
});
//return wordLenghts;
return Math.max.apply(Math, wordLenghts)
//return str.length;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
//////////
function findLongestWord(str) {
var words = str.split(' ');
var wordLenghts = words.map(function(val){
return val.length;
});
// return Math.max.apply(Math, wordLenghts)
return Math.max.apply(null, wordLenghts)
}
findLongestWord("The quick brown fox jumped over the lazy dog");
// capitalize words
function titleCase(str) {
var words = str.split(' ');
var wordsCap = words.map(function(val){
return val.charAt(0).toUpperCase() + val.substr(1).toLowerCase();
});
return wordsCap.join(" ");
}
titleCase("I'm a little tea pot");
// Return Largest Numbers in Arrays
function largestOfFour(arr) {
var maxArray = [];
for (var i = 0; i < arr.length; i++) {
maxArray.push(Math.max.apply(null, arr[i]));
}
return maxArray;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
/// check if ending is the same as target
function confirmEnding(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
var ending = str.substr(-(target.length));
return (ending == target);
}
confirmEnding("Bastian", "n");
// multiply string
function repeatStringNumTimes(str, num) {
// repeat after me
if (num < 1) return '';
var output = '';
for (var i = 0; i<num; i++){
output += str;
}
return output;
}
repeatStringNumTimes("abc", 3);
/// return string specific length
function truncateString(str, num) {
//var output = '';
if (str.length > num){
// truncate
if (num < 4){
// ... does not add to length
return str.substr(0, num)+ "...";
} else {
// ... does add
return str.substr(0, num-3)+ "...";
}
} else {
return str;
}
}
truncateString("A-tisket a-tasket A green and yellow basket", 11);
//// chunky-monkey
function chunkArrayInGroups(arr, size) {
var newArray = [];
while (arr.length > 0){
var tempArray = [];
if(arr.length < size){size = arr.length;}
for(var i=0; i<size; i++){
tempArray.push(arr[i]);
}
newArray.push(tempArray);
arr = arr.slice(size);
}
return newArray;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
// slasher-flick
function slasher(arr, howMany) {
// it doesn't always pay to be first
return arr.slice(howMany);
}
slasher([1, 2, 3], 2);
//mutations
function mutation(arr) {
//var word = arr[0].split('');
var array2 = arr[1].toLowerCase().split('');
var out = 0;
for (var i=0; i < array2.length; i++){
out = arr[0].toLowerCase().indexOf(array2[i]);
if(out <0) return false;
}
return true;
}
mutation(["hello", "hey"]);
// falsy
function bouncer(arr) {
// Don't show a false ID to this bouncer.
function isBigEnough(value) {
return !!value;
}
var filtered = arr.filter(isBigEnough);
return filtered;
}
bouncer([7, "ate", "", false, 9]);
// another way for falsy bouncer:
function bouncer(arr) {
// Don't show a false ID to this bouncer.
function isBigEnough(value) {
//return !!value; // this works too
return value ? true : false;
}
var filtered = arr.filter(isBigEnough);
return filtered;
}
bouncer([7, "ate", "", false, 9]);
// remove some values, destroyer
function destroyer(arr) {
// Remove all the values
arg = Array.from(arguments);
function myFilter(value) {
//return !!value; // this works too
for (var i=1; i < arguments.length; i++){
out = arg.indexOf(value);
}
if(out < 0) return value;
//return (out > -1) value;
// return value >= 10;
}
var filtered = arr.filter(myFilter);
return filtered;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
// where do I belong
function getIndexToIns(arr, num) {
// Find my place in this sorted array.
arr.sort(function(a, b) {
return a - b;
});
var index = 0;
//return arr;
for (var i=0; i < arr.length; i++){
if(arr[i] >= num){
//index = i;
return i;
}
//out = arg.indexOf(value);
}
return i;
//return index;
}
getIndexToIns([70, 40, 60], 50);
// rot13 roman enqryption. table: http://www.asciitable.com/
function rot13(str) { // LBH QVQ VG!
var output = '';
for (var i =0; i<str.length; i++){
// var c = str.charCodeAt(i);
if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) { // 78-103, or 65 - 90
var newC = str.charCodeAt(i)-13;
if(newC<65){
// e ==69; 69-13=57;
// 65-57=8; 90-8=82;
// 90-(65-57)=82; // 57 is the variable
// 90-(65-str.charCodeAt(i))=82; // 57 is the variable
output += String.fromCharCode(91-(65-newC));
}else{
output += String.fromCharCode(newC);
}
} else {
output += String.fromCharCode(str.charCodeAt(i));
}
}
return output;
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
////////// jquery click
<script>
$(document).ready(function() {
$("#getMessage").on("click", function(){
// Only change code below this line.
$(".message").html("Here is the message");
// Only change code above this line.
});
});
</script>
<div class="container-fluid">
<div class = "row text-center">
<h2>Cat Photo Finder</h2>
</div>
<div class = "row text-center">
<div class = "col-xs-12 well message">
The message will go here
</div>
</div>
<div class = "row text-center">
<div class = "col-xs-12">
<button id = "getMessage" class = "btn btn-primary">
Get Message
</button>
</div>
</div>
</div>
/////////// get json api
<script>
$(document).ready(function() {
$("#getMessage").on("click", function(){
// Only change code below this line.
$.getJSON("/json/cats.json", function(json) {
$(".message").html(JSON.stringify(json));
});
// Only change code above this line.
});
});
</script>
<div class="container-fluid">
<div class = "row text-center">
<h2>Cat Photo Finder</h2>
</div>
<div class = "row text-center">
<div class = "col-xs-12 well message">
The message will go here
</div>
</div>
<div class = "row text-center">
<div class = "col-xs-12">
<button id = "getMessage" class = "btn btn-primary">
Get Message
</button>
</div>
</div>
</div>
//////////////// convert JSON to HTML
<script>
$(document).ready(function() {
$("#getMessage").on("click", function() {
$.getJSON("/json/cats.json", function(json) {
var html = "";
// Only change code below this line.
json.forEach(function(val) {
var keys = Object.keys(val);
html += "<div class = 'cat'>";
keys.forEach(function(key) {
html += "<strong>" + key + "</strong>: " + val[key] + "<br>";
});
html += "</div><br>";
});
// Only change code above this line.
$(".message").html(html);
});
});
});
</script>
<div class="container-fluid">
<div class = "row text-center">
<h2>Cat Photo Finder</h2>
</div>
<div class = "row text-center">
<div class = "col-xs-12 well message">
The message will go here
</div>
</div>
<div class = "row text-center">
<div class = "col-xs-12">
<button id = "getMessage" class = "btn btn-primary">
Get Message
</button>
</div>
</div>
</div>
/////////////////// render JSON On HTML
<script>
$(document).ready(function() {
$("#getMessage").on("click", function() {
$.getJSON("/json/cats.json", function(json) {
var html = "";
json.forEach(function(val) {
html += "<div class = 'cat'>";
// Only change code below this line.
html += "<img src = '" + val.imageLink + "' " + "alt='" + val.altText + "'>";
// Only change code above this line.
html += "</div>";
});
$(".message").html(html);
});
});
});
</script>
<div class="container-fluid">
<div class = "row text-center">
<h2>Cat Photo Finder</h2>
</div>
<div class = "row text-center">
<div class = "col-xs-12 well message">
The message will go here
</div>
</div>
<div class = "row text-center">
<div class = "col-xs-12">
<button id = "getMessage" class = "btn btn-primary">
Get Message
</button>
</div>
</div>
</div>
////// JSON filtering on HTML
<script>
$(document).ready(function() {
$("#getMessage").on("click", function() {
$.getJSON("/json/cats.json", function(json) {