“plasterek” Kod odpowiedzi

Zwróć dwa ostatnie wartości tablicy w JavaScript

arr.slice(Math.max(arr.length - 5, 1))
Fancy Fox

JavaScript Slice Tray

// array.slice(start, end)
const FRUITS = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
var citrus = FRUITS.slice(1, 3);
// citrus => [ 'Orange', 'Lemon' ]

// Negative values slice in the opposite direction
var fromTheEnd = FRUITS.slice(-3, -1);
// fromTheEnd => [ 'Lemon', 'Apple' ]
deadlymuffin

Tablica kopii JavaScript

var oldColors=["red","green","blue"];
var newColors = oldColors.slice(); //make a clone/copy of oldColors
Grepper

Tablica wycięta tylko ostatnie 5 elementów

arr.slice(Math.max(arr.length - 5, 0))
Condemned Camel

JavaScript Jak zdobyć podarunę

const ar  = [1, 2, 3, 4, 5];

// slice from 1..3 - add 1 as the end index is not included

const ar2 = ar.slice(1, 3 + 1);

console.log(ar2);
Stormy Seal

plasterek

Concept:
s[x:y:z] , x- left index , y-1 - right index 
z is the number of steps of jumping between 2 chr 
if z>0 :
    direction of jump is right to left(R2L)
else:
    direction of jump is left to right(L2R)
s[:3] means x=0,y=2,z=1
s[3:] means x=3,y=len(s)-1,z=1

examples:

s="dbdhdhndnbdd"
print(s[2:6:2])
//prints dd as left index is 2 right is 5 -> substring is dhdh & 2 means d,skip h,then d
s="djdjcjfd"
print(s[::-2])
//prints djjj, left index is 0 ,right is len(s)-1 -> substring is djdjcjfd & 
//-2 means start from right side in substring in steps of 2-> d,skip f,then j,skip c,then j & j
ap_Cooperative_dev

Odpowiedzi podobne do “plasterek”

Pytania podobne do “plasterek”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu