Skip to content

Commit eeda397

Browse files
committed
Add
1 parent 3cac257 commit eeda397

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

2023-07-15.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// https://www.codewars.com/kata/559590633066759614000063/train/javascript
2+
function minMax( arr ) {
3+
return [ Math.min( ...arr ), Math.max( ...arr ) ];
4+
}
5+
6+
console.log( minMax( [ 1, 2, 3, 4, 5 ] ) ); // :>> 1, 5
7+
console.log( minMax( [ 2334454, 5 ] ) ); // :> 5, 2334454
8+
console.log( minMax( [ 5 ] ) ); // :>> 5, 5
9+
10+
11+
12+
// https://www.codewars.com/kata/5769b3802ae6f8e4890009d2/javascript
13+
function removeEveryOther( arr ) {
14+
return arr.filter( ( e, i ) => i % 2 === 0 );
15+
}
16+
console.log( removeEveryOther( [ 'Hello', 'Goodbye', 'Hello Again' ] ) ); // :>> ['Hello', 'Hello Again']
17+
console.log( removeEveryOther( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] ) ); // :>> [1, 3, 5, 7, 9]
18+
19+
20+
21+
// https://www.codewars.com/kata/58f5c63f1e26ecda7e000029/train/javascript
22+
function wave( str ) {
23+
const mexicanWave = [];
24+
for ( let i = 0; i < str.length; i++ ) {
25+
if ( /\s/.test( str[i] ) ) continue;
26+
const waveState = str.slice( 0, i ) + str[i].toUpperCase() + str.slice( i + 1 );
27+
mexicanWave.push( waveState );
28+
}
29+
return mexicanWave;
30+
}
31+
console.log( wave( 'hello' ) ); // :>> ["Hello", "hEllo", "heLlo", "helLo", "hellO"]
32+
console.log( wave( 'codewars' ) );
33+
console.log( wave( '' ) );
34+
console.log( wave( 'two words' ) );
35+
36+
37+
38+
// https://www.codewars.com/kata/5b853229cfde412a470000d0/train/javascript
39+
function twiceAsOld( dad, son ) {
40+
return dad > son*2 ? dad - son*2 : son*2 - dad;
41+
}
42+
console.log( twiceAsOld( 36, 7 ) ); // :>> 22
43+
console.log( twiceAsOld( 55, 30 ) ); // :>> 5
44+
console.log( twiceAsOld( 42, 21 ) ); // :>> 0
45+
console.log( twiceAsOld( 29, 0 ) ); // :>> 29
46+
// others solution, "Math.abs()" gives the difference
47+
function twiceAsOld2( dad, son ) {
48+
return Math.abs( dad - son*2 );
49+
}
50+
console.log( twiceAsOld2( 36, 7 ) ); // :>> 22
51+
console.log( twiceAsOld2( 55, 30 ) ); // :>> 5
52+
console.log( twiceAsOld2( 42, 21 ) ); // :>> 0
53+
console.log( twiceAsOld2( 29, 0 ) ); // :>> 29

0 commit comments

Comments
 (0)