Skip to content

Commit 18c5e1c

Browse files
authored
Merge pull request doocs#52 from limbowandering/master
add javascript solutions
2 parents 6f334e0 + e184f03 commit 18c5e1c

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const missingNumber = function(nums){
2+
return (1 + nums.length)*nums.length/2 - nums.reduce((prev,cur)=>prev+=cur, 0);
3+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const isPowerOfThree1 = function(n){
2+
return n <= 2? n === 1 : isPowerOfThree(n/3);
3+
};
4+
//44%;
5+
6+
const isPowerOfThree2 = function(n){
7+
const Max3PowerInt = 1162261467;
8+
const MaxInt = 2147483647;
9+
return n <= 0 || n > Max3PowerInt ? false: Max3PowerInt % n === 0;
10+
}
11+
//96%;
12+
13+
const isPowerOfThree = function(n){
14+
let t = Math.log10(n)/Math.log10(3);
15+
return Number.isInteger(t);
16+
}
17+
//22%

solution/412.Fizz Buzz/Solution.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const fizzBuzz = function(n){
2+
let arr = [];
3+
for(let i = 1; i <= n; i++){
4+
if(i % 15 === 0) arr.push('FizzBuzz');
5+
else if(i % 3 === 0) arr.push('Fizz');
6+
else if(i % 5 === 0) arr.push('Buzz');
7+
else arr.push(`${i}`);
8+
}
9+
return arr;
10+
};

0 commit comments

Comments
 (0)