This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function isPalindrome(s) { | |
| let len = s.length; | |
| for (let i = 0; i < Math.floor(len / 2); i++) { | |
| if (s.charAt(i) !== s.charAt(len - i - 1)) { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function gcd(a, b) { //greatest common divisor | |
| if(isNaN(a) || isNaN(b)){ | |
| //throw new Error("a or b should be a number"); | |
| //console.log('a or b should be a number'); | |
| return false; | |
| } | |
| if(Math.floor(a) !== a || Math.floor(b) !== b){ | |
| //throw new Error("a or b should be an integer"); | |
| //console.log('a or b should be an integer'); | |
| return false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function isPrime(num) { | |
| if(num === 2 || num === 3){ | |
| return true; | |
| } | |
| for(let i =2; i<=Math.floor(Math.sqrt(num)); i++){ | |
| if(num % i === 0){ | |
| return false; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function largestProductinaSeries(n) { | |
| // Good luck! | |
| let thousandDigits = [7,3,1,6,7,1,7,6,5,3,1,3,3,0,6,2,4,9,1,9,2,2,5,1,1,9,6,7,4,4,2,6,5,7,4,7,4,2,3,5,5,3,4,9,1,9,4,9,3,4,9,6,9,8,3,5,2,0,3,1,2,7,7,4,5,0,6,3,2,6,2,3,9,5,7,8,3,1,8,0,1,6,9,8,4,8,0,1,8,6,9,4,7,8,8,5,1,8,4,3,8,5,8,6,1,5,6,0,7,8,9,1,1,2,9,4,9,4,9,5,4,5,9,5,0,1,7,3,7,9,5,8,3,3,1,9,5,2,8,5,3,2,0,8,8,0,5,5,1,1,1,2,5,4,0,6,9,8,7,4,7,1,5,8,5,2,3,8,6,3,0,5,0,7,1,5,6,9,3,2,9,0,9,6,3,2,9,5,2,2,7,4,4,3,0,4,3,5,5,7,6,6,8,9,6,6,4,8,9,5,0,4,4,5,2,4,4,5,2,3,1,6,1,7,3,1,8,5,6,4,0,3,0,9,8,7,1,1,1,2,1,7,2,2,3,8,3,1,1,3,6,2,2,2,9,8,9,3,4,2,3,3,8,0,3,0,8,1,3,5,3,3,6,2,7,6,6,1,4,2,8,2,8,0,6,4,4,4,4,8,6,6,4,5,2,3,8,7,4,9,3,0,3,5,8,9,0,7,2,9,6,2,9,0,4,9,1,5,6,0,4,4,0,7,7,2,3,9,0,7,1,3,8,1,0,5,1,5,8,5,9,3,0,7,9,6,0,8,6,6,7,0,1,7,2,4,2,7,1,2,1,8,8,3,9,9,8,7,9,7,9,0,8,7,9,2,2,7,4,9,2,1,9,0,1,6,9,9,7,2,0,8,8,8,0,9,3,7,7,6,6,5,7,2,7,3,3,3,0,0,1,0,5,3,3,6,7,8,8,1,2,2,0,2,3,5,4,2,1,8,0,9,7,5,1,2,5,4,5,4,0,5,9,4,7,5,2,2,4,3,5,2,5,8,4,9,0,7,7,1,1,6,7,0,5,5,6,0,1,3,6,0,4, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function specialPythagoreanTriplet(n) { | |
| let i, j, k; | |
| for(i=1; i<Math.floor(n/2); i++){ | |
| for(j=i+1; j<Math.floor(n/2); j++){ | |
| k = n-i-j; | |
| if(i**2 + j**2 === k**2){ | |
| return i*j*k; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function isPrime(num) { | |
| if(num === 2 || num === 3){ | |
| return true; | |
| } | |
| for(let i =2; i<=Math.floor(Math.sqrt(num)); i++){ | |
| if(num % i === 0){ | |
| return false; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function largeSum(arr) { | |
| let sum = 0; | |
| let len = arr.length; | |
| let i, j; | |
| let newArr = []; | |
| for(i=0; i<len; i++){ | |
| let item = arr[i].slice(0,13); //The later part of digits will not affect the first 10 digits. | |
| let num = parseInt(item); | |
| newArr.push(num); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function handleNum (n){ | |
| if(n%2 === 0){ | |
| n = n/2; | |
| }else{ | |
| n = 3*n+1; | |
| } | |
| return n; | |
| } | |
| //console.log(handleNum (8)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function digitFibonacci(n) { | |
| let a = 1; | |
| let b = 1; | |
| let i = 2; | |
| while(('' + b).length < n){ | |
| [a, b] = [b, a+b]; | |
| i++ | |
| } | |
| // Good luck! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function distinctPowers(n) { | |
| // Good luck! | |
| let i, j, k; | |
| let arr = []; | |
| for(i=2; i<=n; i++){ | |
| for(j=2; j<=n; j++){ | |
| let flag = true; | |
| let item = i**j; | |
| for(k=0; k<arr.length; k++){ |