Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
1-liner: slice & concat solution in Uncategorized category for Replace First by --Serial_Sniper--
import assert from "assert";
function replaceFirst(values){return values.slice(1).concat(values.slice(0,1));}
console.log('Example:');
console.log(replaceFirst([1, 2, 3, 4]));
// These "asserts" are used for self-checking
assert.deepEqual(replaceFirst([1, 2, 3, 4]), [2, 3, 4, 1]);
assert.deepEqual(replaceFirst([1]), [1]);
assert.deepEqual(replaceFirst([]), []);
console.log("Coding complete? Click 'Check' to earn cool rewards!");
June 6, 2020