博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codewars练习(javascript)-2021/1/28
阅读量:733 次
发布时间:2019-03-22

本文共 1822 字,大约阅读时间需要 6 分钟。

文章目录

codewars-js练习

2021/1/28

github 地址

【1】<7kyu>【Simple Fun #176: Reverse Letter】

Given a string str, reverse it omitting all non-alphabetic characters.

example

For str = "krishan", the output should be "nahsirk".For str = "ultr53o?n", the output should be "nortlu".

solution

【2】<7kyu>【Find the middle element】

As a part of this Kata, you need to create a function that when provided with a triplet, returns the index of the numerical element that lies between the other two elements.

The input to the function will be an array of three distinct numbers (Haskell: a tuple).

您需要创建一个函数,当提供三元组时,返回位于其他两个元素之间的数值元素的索引。函数的输入将是一个由三个不同数字组成的数组(Haskell:一个元组)。

example

gimme([2, 3, 1]) // 0 -> 2 is the number that fits between 1 and 3 and the index of 2 in the input array is 0.gimme([5, 10, 14]) // 1 -> 10 is the number that fits between 5 and 14 and the index of 10 in the input array is 1.

solution

【3】<7kyu>【Vowel Count】

Return the number (count) of vowels in the given string.

We will consider a, e, i, o, u as vowels for this Kata (but not y).

The input string will only consist of lower case letters and/or spaces.

返回给定字符串中元音的数量(count)。输入只包含小写字母或空格

example

getCount("abracadabra")// 5

solution

【4】<7kyu>【Alternate capitalization】

Given a string, capitalize the letters that occupy even indexes and odd indexes separately, and return as shown below. Index 0 will be considered even.

给定一个字符串,将占用偶数索引和奇数索引的字母分别大写,并返回如下所示。索引0将被认为是偶数。

example

capitalize("abcdef")// ['AbCdEf', 'aBcDeF']

solution

【5】<7kyu>【Form The Minimum】

Given a list of digits, return the smallest number that could be formed from these digits, using the digits only once (ignore duplicates).

给定一个数字列表,返回可以由这些数字组成的最小数字,只使用这些数字一次(忽略重复)。

example

minValue ([1, 3, 1])  // return (13)minValue([5, 7, 5, 9, 7])  // return (579)

solution

以上为自己思路供大家参考,可能有更优的思路。

转载地址:http://uvdwk.baihongyu.com/

你可能感兴趣的文章