[JS Practice] Sort characters

Title :

Sort characters

Description:

Write a function called sortGiftCode (sort_gift_code in Ruby) that accepts a string containing up to 26 unique alphabetical characters, and returns a string containing the same characters in alphabetical order.

Examples:

sortGiftCode( 'abcdef' );//=> returns 'abcdef'
sortGiftCode( 'pqksuvy' );//=> returns 'kpqsuvy'
sortGiftCode( 'zyxwvutsrqponmlkjihgfedcba' );
//=> returns 'abcdefghijklmnopqrstuvwxyz'

Continue reading

[JS Practice] Difference of 2 (相差2)

Title :

Difference of 2

Description:

The objective is to obtain the various sets of integers that have a difference of 2 from a given array of integers. The result array should be sorted in ascending order of values.

So for example for the array of integers

[1,2,3,4] should return [[1,3],[2,4]]

[4,1,2,3] should also return [[1,3],[2,4]]

[1,23,3,4,7] should return [[1,3]]

Assume there are no duplicate integers in the array. The order of the integers in the input array should not matter.

Continue reading