Comments

19 days ago

const solve = (intArray, k) => { const val = (k + 1) * -1; return intArray.splice(val)[0]; };

a month ago

const solve = (intArray, k) => { k = ++k return intArray.splice(-k)[0]; };

6 months ago

` const solve = (intArray, k) => { return intArray[(intArray.length -1) - k]; };`

6 months ago

value give in constant time return intArray[intArray.length-k-1];

6 months ago

const solve = (intArray, k) => intArray.reverse()[k];

7 months ago

const solve = (intArray, k) => { intArray.reverse() return intArray[k] };

8 months ago

O(1)

``````const solve = (intArray, k) => {
return intArray[intArray.length-k-1];
};

``````

8 months ago

const solve = (intArray, k) => { return intArray[intArray.length - k - 1] }

8 months ago

const solve = (intArray, k) => {

let counter = 0;

for(let i = (intArray.length-1); i >= 0; i--){

``````if(counter === k){
return intArray[i];
}
counter++;
``````

}

};

8 months ago

You can avoid a runtime complexity of O(n) or a linear runtime complexity with a for loop .If you already know the length of the array, you can do intArray.length-k go go backwards for 3 steps.As arrays index start from 0, you should substract the result of the previous calculation by 1.And the runtime complexity of your will become constant or O(1)

`return intArray[intArray.length-k-1];`

9 months ago

return intArray.reverse()[k];

10 months ago

if there are no rules const solve = (intArray, k) => {

return intArray.reverse()[k]; };

10 months ago

``````const solve = (intArray, k) => {
return intArray.slice(intArray.length, intArray.length-k)

};
``````

4 months ago

Sorry it passed the test but it should'nt because of zero

10 months ago

``````const solve = (intArray, k) => {
return intArray.slice(intArray.length, intArray.length-1)

};``````

2 years ago

below code also gives correct results. when i click submit it says no u dont qualify you fail. not sure what evaluation criteria is. but anyhow my results are also correct with below code

const solve = (intArray, k) => { let intArray1 = intArray.toString().replace(/[,-]/g, ""); return intArray1.charAt(intArray1.length-k-1); };

2 years ago

`const solve = (intArray, k) => { return intArray.find((el, i) => k === Math.abs( i - (intArray.length-1))); };`

2 years ago

const solve = (intArray, k) => { return intArray.reverse()[k]; };

a year ago

Acturally, you may omit { return } (curly braces and "return" key word.

2 years ago

Don't get too complicated!

``````const solve = (intArray, k) => {
return intArray[intArray.length - k - 1];
};
``````

a year ago

This was exactly my solution and 'something went terribly wrong'.