Comments

Anurag Arwalkar19 days ago

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

Cambridgeshire Computers Leka month ago

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

Ali Sequeira6 months ago

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

Akash6 months ago

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

Mobility Grenada6 months ago

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

Batdemberel7 months ago

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

Christian Lisangola8 months ago

O(1)

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

Matheus Felipe Trinca8 months ago

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

Mac Villegas8 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++;

}

};

Christian Lisangola8 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];

Fatih KAYA9 months ago

return intArray.reverse()[k];

protocol10 months ago

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

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

newyorkcityjose10 months ago

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

newyorkcityjose4 months ago

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

newyorkcityjose10 months ago

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

zunair jarral2 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); };

Omar Gerardo Rodriguez Aramburo2 years ago

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

Mouse Tools2 years ago

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

Ameliorated Tugrika year ago

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

Stephen Grider2 years ago

Don't get too complicated!

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

catherine f healeya year ago

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