7 kyu

Easy mathematical callback

859 of 7,381nghier

Description:

Task

Write the processArray function, which takes an array and a callback function as parameters. The callback function can be, for example, a mathematical function that will be applied on each element of this array. Optionally, also write tests similar to the examples below.

Examples

  1. Array [4, 8, 2, 7, 5] after processing with function

    var myArray = [4, 8, 2, 7, 5];
    myArray = processArray(myArray,function (a) {
      return a * 2;
    });
    
    function(a): return a*2;
    
    Kata.ProcessArray(new int[] {4, 8, 2, 7, 5}, (Func<int, int>)((v) => v * 2));
    

    will be [ 8, 16, 4, 14, 10 ].

  2. Array [7, 8, 9, 1, 2] after processing with function

    var myArray = [7, 8, 9, 1, 2];
    myArray = processArray(myArray, function (a) {
      return a + 5;
    });
    
    function(a): return a+5;
    
    Kata.ProcessArray(new int[] {7, 8, 9, 1, 2}, (Func<int, int>)((v) => v + 5));
    

    will be [ 12, 13, 14, 6, 7 ].

Algorithms

Similar Kata:

Stats:

CreatedJan 15, 2015
PublishedJan 15, 2015
Warriors Trained10351
Total Skips354
Total Code Submissions23745
Total Times Completed7381
JavaScript Completions6499
Python Completions859
C# Completions126
Total Stars55
% of votes with a positive feedback rating84% of 584
Total "Very Satisfied" Votes450
Total "Somewhat Satisfied" Votes83
Total "Not Satisfied" Votes51
Ad
Contributors
  • nghier Avatar
  • joh_pot Avatar
  • goodwin64 Avatar
  • bouchert Avatar
  • Souzooka Avatar
  • rowcased Avatar
  • FArekkusu Avatar
  • hobovsky Avatar
  • saudiGuy Avatar
Ad