An Introduction to the Map-Reduce Pattern

Published by Николай in

You will be implementing a basic case of the map-reduce pattern in programming. Given a vector stored as an array of numbers, find the magnitude of the vector. Use the standard distance formula for n-dimensional Cartesian coordinates.

Examples

Magnitude([3, 4]) ➞ 5

Magnitude([0, 0, -10]) ➞ 10

Magnitude([]) ➞ 0

Magnitude([2, 3, 6, 1, 8] ) ➞ 10.677078252031311

Notes

  • The array can have any length.
  • The input array will contain integers (except for empty array [] ➞ 0).
  • Write your own .map() and .reduce() methods in your solution or use these queries through LINQ (don't forget to connect the library System.Linq).
Watch a quick demo on how Edabit works.