Don't LeetCode Yet - 5 - Classic Problems
10 classic problems. Try not to use built-in functions/methods but only iteration, condition, and self-written functions.
Only use the necessary ones: split(), floor() ……
Check arithmetic sequence
Loop through 0 to input.length-2, and let num1 = input[0], num2 = input[1], num3=[2]
Check if they have the same subtraction value.
Better check for edge case like only 1 or 2 numbers, input strings, no input…etc.
| function isArith(input) { | 
Check Taiwan ID
| function TWIDChecker(input){ | 
Add up all digits in a number
Project 5
LIOJ problem 1026
Check Geometric sequence
Same as Arithmetic sequence
LIOJ problem 1027
Check Credit card number
LIOJ problem 1028
I didn’t think about the birthdays like “2999 6 30” or “3999 12 31”, so I use if while checking if the number is more than 2 digits, witch will only check once.
But here we need to use while in order to loop through all the cases(in case there are more than 3 digits):
| while (lifeCode >= 10){ | 
LIOJ problem 1034
When try to find the new ASCII code, if the added number is more than 27, there will be a problem if we only subtract 26.
ex: z will become { adding 26a will also become { adding 52.
So the added number should be divided by 26 and use the remainder.
| let newCharCode = orgStr.charCodeAt(i)+addNum % 26 | 
LIOJ problem 1030
Check if it’s PALINDROME (what a word!)
Two ways : 1. Reverse the original string 2. Compaire the (first + n) and (last - n) character…etc.
LIOJ problem 1031
Square pyramidal number sequence
1 + 121 + 12321 + 1234321 +  ……
| function solve(lines){ | 
Or just simply check if a number is squared, and add them up!
LIOJ problem 1032
Practice the usage of Math.sart, Math.abs, Math.toFixed()
LIOJ problem 1033
| let dots =[] | 
This will get the data look like:
| [{x:1, y:2}, | 
LIOJ problem 1046
Brute-force or some simple loops for 3 vertical and 3 horizontal lines
multidimensional arrays