7 kyu

Zip it!

427 of 986joh_pot

Description:

Write

Array.prototype.zip = function (arr, fn) {}
Array#zip
lstzip

that merges the corresponding elements of two sequences using a specified selector function fn (a block in Ruby)

For example:

var a = [1, 2, 3, 4, 5];
var b = ['a','b'];
a.zip(b, (a, b) => a + b) === ['1a', '2b']

var a = [1, 2, 3, 4, 5];
var b = ['a','b','c','d','e'];
a.zip(b, (a, b) => a + b.charCodeAt(0)) === [98, 100, 102, 104, 106]
var a = new object[] { 1, 2, 3, 4, 5 };
var b = new object[] { 'a','b' };
a.ZipIt(b, (c, d) => c + "" + d); --> new object[] { '1a', '2b' }

var a = new object[] { 1, 2, 3, 4, 5 };
var b = new object[] {'a','b','c','d','e'};
a.ZipIt(b, (c, d) => (int)c + (int)(char)d)); --> new object[] { 98, 100, 102, 104, 106 }
a = [1, 2, 3, 4, 5]
b = ['a', 'b']
a.zip(b){|x, y| x.to_s + y} => ['1a', '2b']

a = [1, 2, 3, 4, 5]
b = ['a','b','c','d','e']
a.zip(b){|x, y| x + y.ord} => [98, 100, 102, 104, 106]
a = [1, 2, 3, 4, 5]
b = ['a', 'b']
lstzip(a,b, lambda a,b: str(a)+str(b))

a = [1, 2, 3, 4, 5]
b = ['a','b','c','d','e']
lstzip(a,b, lambda a, b: a * ord(b[0]))

if arrays have different lengths, go up to the minimum length and then stop.

Arrays
Fundamentals

Similar Kata:

Stats:

CreatedJan 29, 2016
PublishedJan 29, 2016
Warriors Trained2007
Total Skips143
Total Code Submissions3519
Total Times Completed986
JavaScript Completions427
Ruby Completions84
Python Completions398
C# Completions75
C Completions71
Total Stars32
% of votes with a positive feedback rating90% of 246
Total "Very Satisfied" Votes209
Total "Somewhat Satisfied" Votes27
Total "Not Satisfied" Votes10
Total Rank Assessments11
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • joh_pot Avatar
  • GiacomoSorbi Avatar
  • NaMe613 Avatar
  • user5036852 Avatar
  • lilsweetcaligula Avatar
  • FArekkusu Avatar
  • user9644768 Avatar
  • hobovsky Avatar
  • farhanaditya Avatar
Ad