Skip to content

Instantly share code, notes, and snippets.

View jialinhuang00's full-sized avatar
๐Ÿ˜ƒ

jialin.huang jialinhuang00

๐Ÿ˜ƒ
View GitHub Profile
Name Character Entity
Copyright ยฉ ©
Registered ยฎ ®
Trademark โ„ข ™
Curly Open Double Quote โ€œ “
Curly Closed Double Quote โ€ ”
Curly Open Single Quote โ€˜ ‘
Curly Closed Single Quote โ€™ ’
Big Bullet/Dot โ€ข •
/*-----------------------------------------------------------------------------
1.check the multiple
2.the fifteen's case must be first.
the reference is from UdemyCourse: LearningAlgorithmsInJavascriptFromScratch
-----------------------------------------------------------------------------*/
// 15X ->> 'FizzBuzz'
// 5X ->> 'buzz'
// 3X ->> 'fizz'
function fizbuz(n) {
/*-----------------------------------------------------------------------------
1.check if the 1st argument's words is existing at the 2nd argument.
2.the function is used to check if the latter is more apples than the former.
the reference is from UdemyCourse: LearningAlgorithmsInJavascriptFromScratch
-----------------------------------------------------------------------------*/
/*๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ๏ผŠ
NOTES๏ผšTime complexity, Big O notation๏ผˆ๏ผ‰
/*-----------------------------------------------------------------------------
1.check if the string that reversed is as same as the origin.
2.ignoring the situation like upper or lower, and punctuation.
the reference used at the second function is from UdemyCourse: LearningAlgorithmsInJavascriptFromScratch
-----------------------------------------------------------------------------*/
function isPalindrome(string) {
var reg = /[a-z]/g;
/*-----------------------------------------------------------------------------
1.turn every word into another word by the same process.
2.just like a puzzle
3.the map() method need to assigned to a variable.
the reference is by me, oh yah.
-----------------------------------------------------------------------------*/
function caesarCipher(str, num) {
arr = str.split("");
/*-----------------------------------------------------------------------------
1.reverse every word in the sentence.
2.the orders between words do not change.
the reference used at the second function is from UdemyCourse: LearningAlgorithmsInJavascriptFromScratch
-----------------------------------------------------------------------------*/
function reverseWords(str) {
return str.split('').reverse().join('');
}
/*-----------------------------------------------------------------------------
1.swap the elements
2.temporary variable is useful.
the reference is from UdemyCourse: LearningAlgorithmsInJavascriptFromScratch
-----------------------------------------------------------------------------*/
function reverseArrayInPlace(arr) {
// dsakhpr d <-> r s <-> p a <-> h
/*-----------------------------------------------------------------------------
1.3 function used to calculate: mean, median, mode.
2.writing another function to package them.
3.MODE: if there is no number repeated, return false.
3.MODE: maybe there is not only one mode.
the reference is from UdemyCourse: LearningAlgorithmsInJavascriptFromScratch
-----------------------------------------------------------------------------*/
function meanMedianMode(arr) {
/*-----------------------------------------------------------------------------
1.pair off for the required parameter 'sum'.
2.the former by myself is using two loops
3.two ways turned out to be different.
the reference used at the second function is from UdemyCourse: LearningAlgorithmsInJavascriptFromScratch
-----------------------------------------------------------------------------*/
function twoSum(numArr, sum) {
// scrutinize every element
/*-----------------------------------------------------------------------------
the reference is from UdemyCourse: LearningAlgorithmsInJavascriptFromScratch
-----------------------------------------------------------------------------*/
function binarySearch(numArr, key) {
numArr = numArr.sort((a, b) => a - b);
var midIndex = Math.floor(numArr.length / 2);
var midElement = numArr[midIndex];