Fibonacci number array flip + + + sorted array is determined leap year

Seeking Fibonacci Fibonacci n-th column number is how much? 2. 8. 3. 1. 5. 1 13 is 21 is ...
function getFib (n-) {
// function body
var = N1. 1;
var = N2. 1;
var N3;
for (var. 3 = I; I <= n-; I ++) {
N3 N1 + N2 =;
N1 = N2;
N2 = N3;
}
return N3;
}

var r = getFib(6);
console.log(r);

 


Flip list, returns a new array [. 5,. 4,. 3, 2,. 1] -> [. 1, 2,. 3,. 4,. 5]
function Reverse (Array) {
var newArray = [];
for (var I = Array. length -. 1; I> = 0; i--) {
newArray [newArray.length] = Array [I];
}
return newArray;
}

// var arr = [5, 3, 2, 1];
// console.log(reverse(arr));

var arr = ['abc', 'xyz', '123'];
console.log(reverse(arr));

 


Sorting an array, from small to large - bubble sort
function Sort (Array) {
// the number of times the outer loop
for (var I = 0; I <be array.length -. 1; I ++) {
// assumed sorted the
var = isSort to true;
// number of times the inner loop control comparison
for (var J = 0; J <be array.length -. 1 - I; J ++) {
IF (Array [J]> Array [J +. 1]) {
= to false isSort;
// exchange position
var tmp = Array [J];
Array [J] = Array [J +. 1];
Array [J +. 1] = tmp;
}
}
// determines whether a good row
if (isSort) {
BREAK;
}
}
return Array;
}

var array = [34, 12, 88, 20, 30];

console.log(sort(array));
}

 

 

 


Input a year, it is determined whether or not a leap year [leap: 4 can not be an integer and an integer of 100, or can be an integer from 400]
function isRun (year) {
var = Result to false;
IF ((4% === 0 && year year !% 100 == 0) || (400% year === 0)) {
Result = to true;
}
return Result;
}

console.log (isRun (2016));


// input a certain period of a day, this day is judgment day of the year?
@ 1998518
@ May 18
// 30 April
// March 31
// February 29, when leap years, when the balance 28 days
@ 31 January
//
// determines whether the year is a leap year
function isRun (year) {
var = Result to false;
IF (! (year. 4% 100% === == 0 && year 0) || (400% year === 0)) {
Result = to true;
}
return Result;
}
// get the current date is in how many days
function getDays (year, month the, day) {
// calculate the total number of days
var days = day; // number of days in the current month
for (var i = 1; i <month ; I ++) {
Switch (I) {
Case. 1:
Case. 3:
Case. 5:
Case. 7:
Case. 8:
Case 10:
case 12:
days += 31;
break;
case 4:
case 6:
case 9:
case 11:
days += 30;
break;
case 2:
// 判断是平年28还是闰年29
if (isRun(year)) {
days += 29;
} else {
days += 28;
}
break;
}
}
return days;
}

console.log(getDays(1998, 5, 2));

Guess you like

Origin www.cnblogs.com/pxxdbk/p/12560852.html