Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for Replace First by Assper
import assert from "assert";
function replaceFirst(values: number[]): number[] {
const [first, ...rest] = values
return first ? [...rest, first] : [];
}
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!");
April 23, 2020
Comments: