Skip to content

Instantly share code, notes, and snippets.

@icarito
Created March 28, 2022 20:13
Show Gist options
  • Save icarito/0583f606bf998175b20ccfc0366607ff to your computer and use it in GitHub Desktop.
Save icarito/0583f606bf998175b20ccfc0366607ff to your computer and use it in GitHub Desktop.
function elevatorDistance(array) {
const [lastFloor, ...rest] = array;
if (rest.length <= 1) {
return Math.abs(lastFloor - rest[0]);
}
else {
return Math.abs(lastFloor - rest[0]) + elevatorDistance(rest);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment