Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sumAdjacent($a) {
- $res = 0;
- for($i=1; $i<count($a); $i++) ($res += abs($a[$i]-$a[$i-1]));
- return $res;
- }
- echo sumAdjacent([4, 7, 1, 2])."<br>";
- echo sumAdjacent([1, 5, 10, 4, 2])."<br>";
- echo sumAdjacent([1, 1, 1, 1]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement