New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative of SLICE method. #998

Closed
Tech-Engineer opened this Issue Sep 11, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@Tech-Engineer

Tech-Engineer commented Sep 11, 2017

function sliceFunc(origArray, a, b)
{
if(a < 0)
{
a = origArray.length + a;
}
else if(a === undefined)
{
a = 0;
}

if((b<a && b > 0) || b == a)
{
return;
}
else if(b===undefined || b>origArray.length)
{
b=origArray.length;
}
else if(b < 0)
{
b = origArray.length + b;
if(b === a || b < a)
{
return;
}
}

var slicedArray=[];
for(i=a;i<b;i++){
slicedArray.push(origArray[i]);
}
return slicedArray;
}

On frontend we can perform slicing on an array using below syntax:

Present usage of slice method
var numArr = [1, 2, 3, 4, 5];
var subArr = numArr.slice(2, 4);

My proposed way of performing slicing
var numArr = [1, 2, 3, 4, 5];
var subArr = numArr[2...4]; //instead of defining the start and end index by using slice method we can directly define it inside the square bracket.

In my proposed code first number inside square bracket is starting index and second number is end index.

@ljharb

This comment has been minimized.

Show comment
Hide comment
@ljharb

ljharb Sep 11, 2017

Member

Please see https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md#feature-requests - this repo is not for language feature requests.

Member

ljharb commented Sep 11, 2017

Please see https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md#feature-requests - this repo is not for language feature requests.

@ljharb ljharb closed this Sep 11, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment