Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Replace First by kilavki
import assert from "assert";
function replaceFirst(values) {
let x = values.splice(0, 1);
return values.concat(x);
}
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!");
Nov. 11, 2020