7 kyu

Elevator Distance

3,421 of 9,296marbiru

Description:

Imagine you start on the 5th floor of a building, then travel down to the 2nd floor, then back up to the 8th floor. You have travelled a total of 3 + 6 = 9 floors of distance.

Given an array representing a series of floors you must reach by elevator, return an integer representing the total distance travelled for visiting each floor in the array in order.

// simple examples
[5,2,8] => 9
[1,2,3] => 2
[7,1,7,1] => 18

// if two consecutive floors are the same,
//distance travelled between them is 0
[3,3] => 0

Array will always contain at least 2 floors. Random tests will contain 2-20 elements in array, and floor values between 0 and 30.

Fundamentals

More By Author:

Check out these other kata created by marbiru

Stats:

CreatedOct 25, 2017
PublishedOct 25, 2017
Warriors Trained12070
Total Skips165
Total Code Submissions19505
Total Times Completed9296
JavaScript Completions3421
Python Completions3082
Groovy Completions107
Ruby Completions207
Julia Completions20
Rust Completions221
C Completions288
C# Completions374
C++ Completions1751
COBOL Completions9
Haskell Completions54
Scala Completions14
Java Completions64
Total Stars91
% of votes with a positive feedback rating94% of 1054
Total "Very Satisfied" Votes936
Total "Somewhat Satisfied" Votes107
Total "Not Satisfied" Votes11
Total Rank Assessments4
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • marbiru Avatar
  • romerojp Avatar
  • imjasonmiller Avatar
  • JohanWiltink Avatar
  • adrian.eyre Avatar
  • B1ts Avatar
  • ZED.CWT Avatar
  • hobovsky Avatar
  • stellartux Avatar
  • trashy_incel Avatar
  • SergeySinyavskiy Avatar
  • ejini战神 Avatar
  • akar-0 Avatar
  • BobtheLantern Avatar
  • dfhwze Avatar
  • KayleighWasTaken Avatar
  • saudiGuy Avatar
Ad