JavaScript prints the leap year of a given interval year

Time:2021-2-7

requirement:

The user inputs the year interval, start year and end year to be judged, and outputs all leap years in the interval.

Code implementation:

function isRunYear(year) {
    //Return true for leap year, otherwise return false 
    var flag = false;
    if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
        flag = true;
    }
    return flag;
}

function printRunYear(start, end) {
    var runYear = [];
    //Define array to store leap year
    for (var i = start; i <= end; i++) {
        //Traverse all set years
        if (isRunYear(i)) {
            runYear[runYear.length] = i;
        }
        //Call the isrunyear() function to determine whether it is a leap year
        //If it is a leap year, the year is saved in the array
    }
    return runYear;
    //Returns an array of leap years
}
Var start = number (prompt ('Please enter start year: ');
Var end = number (prompt ('Please enter end year: '));
var allRunYear = printRunYear(start, end);
console.log(allRunYear);

Recommended Today

Summary of spark conf and config configuration items

1. State configuration item summary of structured streaming Config Name Description Default Value spark.sql.streaming.stateStore.rocksdb.compactOnCommit Whether we perform a range compaction of RocksDB instance for commit operation False spark.sql.streaming.stateStore.rocksdb.blockSizeKB Approximate size in KB of user data packed per block for a RocksDB BlockBasedTable, which is a RocksDB’s default SST file format. 4 spark.sql.streaming.stateStore.rocksdb.blockCacheSizeMB The size capacity […]