Skip to content

Instantly share code, notes, and snippets.

@Szandor72
Last active March 23, 2021 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Szandor72/41825d6292beb3090dcc2889e060ae8a to your computer and use it in GitHub Desktop.
Save Szandor72/41825d6292beb3090dcc2889e060ae8a to your computer and use it in GitHub Desktop.
A tiny coding challenge
// Given
let array = [0, 1, 2, 3, 4, 5, 6];
let elementsToMove = [2, 3, 4];
// Tasks
// 1)
// Given an arbitrary new index, re order the array so that
// elementsToMove is moved to the correct position
let moveElementsAfterIndex = 5;
let expectedResult1 = [0, 1, 5, 2, 3, 4, 6];
let moveElementsBeforeIndex = 0;
let extectedResult2 = [2, 3, 4, 0, 1, 5, 6];
// 2)
// The same as 1) but your array and elementsToMove should be
// something like [ {id: 0, name: 'zero' },{id: 1, name: 'one'}, {id: 2, name: 'two'}, ...]
// 3)
// How could a solution look like that can solves 1) and 2) at the same time? Is it achievable? Is it prudent? Why? Why not?
// 4)
// should you be familiar with testing, indicate how you would write a tests for your solution(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment