this is my solution in PHP, although the description is quite ambiguous...
$friends = [["A1", "X1"], ["A2", "X2"], ["A3", "X3"], ["A4", "X4"]]; $distances = [["X1", 100], ["X2", 200], ["X3", 350], ["X4", 420]]; $distances = array_reduce($distances, function($x, $y){ $x[$y[0]] = $y[1]; return $x; }); function getTotalDistance($friends, $distances){ $total = 0; for($x = 0; $x < count($friends); $x++){ if(count($friends[$x]) === 2){ $total += ($distances[$friends[$x][1]] * 2); } } return $total; } echo getTotalDistance($friends, $distances);
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
this is my solution in PHP, although the description is quite ambiguous...