diff options
| -rw-r--r-- | challenge-186/kueppo-wesley/Node/ch-1.js | 16 | ||||
| -rw-r--r-- | challenge-186/kueppo-wesley/Node/ch-2.js | 9 | ||||
| -rw-r--r-- | challenge-186/kueppo-wesley/Perl/ch-1.pl | 22 | ||||
| -rw-r--r-- | challenge-186/kueppo-wesley/Perl/ch-2.pl | 35 | ||||
| -rw-r--r-- | challenge-186/kueppo-wesley/Raku/ch-1.raku | 10 | ||||
| -rw-r--r-- | challenge-186/kueppo-wesley/Raku/ch-2.raku | 8 |
6 files changed, 100 insertions, 0 deletions
diff --git a/challenge-186/kueppo-wesley/Node/ch-1.js b/challenge-186/kueppo-wesley/Node/ch-1.js new file mode 100644 index 0000000000..b18b36f5cc --- /dev/null +++ b/challenge-186/kueppo-wesley/Node/ch-1.js @@ -0,0 +1,16 @@ +#!/usr/bin/env node + +'use strict'; + +function zip( ...lists ) { + let results = []; + [ ...Array( lists.map( item => item.length ).sort()[0] ).keys() ].forEach( index => results.push( ...lists.map(item => item[index]) ) ); + return results; +} + +let a = [ 1, 2, 3 ], b = [ 'a', 'b', 'c' ], c = ['e', 'f', ...a ]; + +console.log( zip(a, b) ); +console.log( zip(b, a) ); +console.log( zip(c, a) ); +console.log( zip(b, c, a) ); diff --git a/challenge-186/kueppo-wesley/Node/ch-2.js b/challenge-186/kueppo-wesley/Node/ch-2.js new file mode 100644 index 0000000000..e992e635d0 --- /dev/null +++ b/challenge-186/kueppo-wesley/Node/ch-2.js @@ -0,0 +1,9 @@ +#!/usr/bin/env node + +'use strict'; + +function makeover( ...array ) { + return array.map(string => string.concat(': ', string.normalize('NFKD').slice(0, -1))); +} + +makeover( 'ÃÊÍÒÙ', 'âÊíÒÙ' ).forEach(ascii => console.log(ascii)); diff --git a/challenge-186/kueppo-wesley/Perl/ch-1.pl b/challenge-186/kueppo-wesley/Perl/ch-1.pl new file mode 100644 index 0000000000..eb0e63f1ec --- /dev/null +++ b/challenge-186/kueppo-wesley/Perl/ch-1.pl @@ -0,0 +1,22 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Test::More; + +sub zip { + my ( $a, $b ) = @_; + + # Boils down to iterating over elements + return map { $a->[ $_ ], $b->[ $_ ] } 0 .. ( @$a > @$b ? $#$b : $#$a ); +} + +my @a = qw/1 2 3/; +my @b = qw/a b c/; + +# Testing.. +is_deeply [ zip( \@a, \@b ) ], [ qw/1 a 2 b 3 c/ ], "Zipped?"; +is_deeply [ zip( \@b, \@a ) ], [ qw/a 1 b 2 c 3/ ], "Zipped?"; + +done_testing( 2 ); diff --git a/challenge-186/kueppo-wesley/Perl/ch-2.pl b/challenge-186/kueppo-wesley/Perl/ch-2.pl new file mode 100644 index 0000000000..ddddb1145e --- /dev/null +++ b/challenge-186/kueppo-wesley/Perl/ch-2.pl @@ -0,0 +1,35 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use utf8; + +use Test::More; + +use Encode; +use Unicode::Normalize; + +sub makeover { + my $string = $_[ 0 ]; + + # Decompose unicode characters based on *Compatibility Equivalence* to obtain the + # ascii characters for which impurities have been added to build unicode $string. + $string = NFKD( $string ); + + # Change $string' encoding to ASCII + $string = encode( + 'ascii', + $string, + + # Strip the impurities + sub { '' } + ); + + return $string; +} + +# Testing.. +is( makeover( 'ÃÊÍÒÙ' ), 'AEIOU', "is 'AEIOU' its ascii equivalence?" ); +is( makeover( 'âÊíÒÙ' ), 'aEiOU', "is 'aEiOU' its ascii equivalence?" ); + +done_testing( 2 ); diff --git a/challenge-186/kueppo-wesley/Raku/ch-1.raku b/challenge-186/kueppo-wesley/Raku/ch-1.raku new file mode 100644 index 0000000000..20013e2a28 --- /dev/null +++ b/challenge-186/kueppo-wesley/Raku/ch-1.raku @@ -0,0 +1,10 @@ +#!/usr/bin/env raku + +sub myzip(@a, @b) { + my @result; + for zip(@a, @b) -> [$x, $y] { @result.push($x, $y) } + return @result; +} + +myzip(<a b c>, <1 2 3>).say; +myzip(<1 2 3>, <a b c>).say; diff --git a/challenge-186/kueppo-wesley/Raku/ch-2.raku b/challenge-186/kueppo-wesley/Raku/ch-2.raku new file mode 100644 index 0000000000..45889c6e65 --- /dev/null +++ b/challenge-186/kueppo-wesley/Raku/ch-2.raku @@ -0,0 +1,8 @@ +#!/usr/bin/env raku + +sub makeover( $string ) { + NFKD( $string ).map( { .chr.encode('ascii', :replacement('')).decode('ascii') } ).join().say; +} + +makeover( "ÃÊÍÒÙ" ); +makeover( "âÊíÒÙ" ); |
