“JavaScript Range” Kode Jawaban

JavaScript Range

[...Array(5).keys()];
 => [0, 1, 2, 3, 4]
arvinreydelapena

JavaScript Range

[...Array(5).keys()];
 => [0, 1, 2, 3, 4]
Gifted Gorilla

rentang fungsi () sebagai rentang js

function range(start, end) {
	/* generate a range : [start, start+1, ..., end-1, end] */
	var len = end - start + 1;
	var a = new Array(len);
	for (let i = 0; i < len; i++) a[i] = start + i;
	return a;
}
Puzzled Pollan

JS Range

for (i of range(1, 5)) {
    console.log(i);
}
/* Output
 * 1 2 3 4 5 */

[...range(1, 5)] // [1, 2, 3, 4, 5]
Dead Deer

Rentang angka dalam javascript

function range(start, end) {
    if(start === end) return [start];
    return [start, ...range(start + 1, end)];
}
Shibu Sarkar

berkisar dalam JavaScript

// while ES6 does not have any similar methods built-in 
// the same basic functionality can be implemented by:
[...Array(5).keys()];
 => [0, 1, 2, 3, 4] 

String.fromCharCode(...[...Array('D'.charCodeAt(0) - 'A'.charCodeAt(0) + 1).keys()].map(i => i + 'A'.charCodeAt(0)));
 => "ABCD"

//               OR             //

function range(size, startAt = 0) {
    return [...Array(size).keys()].map(i => i + startAt);
}

function characterRange(startChar, endChar) {
    return String.fromCharCode(...range(endChar.charCodeAt(0) -
            startChar.charCodeAt(0), startChar.charCodeAt(0)))
}
Udituk

Jawaban yang mirip dengan “JavaScript Range”

Pertanyaan yang mirip dengan “JavaScript Range”

Lebih banyak jawaban terkait untuk “JavaScript Range” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya