从 URL 中提取域名
DESCRIPTION
Write a function that when given a URL as a string, parses out just the domain name and returns it as a string.
SOLUTION
- 方法一:
1 | function domainName(url) { |
Write a function that when given a URL as a string, parses out just the domain name and returns it as a string.
1 | function domainName(url) { |
The marketing team is spending way too much time typing in hashtags.
Let’s help them with our own Hashtag Generator!
Here’s the deal:
It must start with a hashtag (#).
All words must have their first letter capitalized.
If the final result is longer than 140 chars it must return false.
If the input or the result is an empty string it must return false.
1 | function generateHashtag(str) { |
Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don’t need to validate the form of the Roman numeral.
Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost digit and skipping any 0s. So 1990 is rendered “MCMXC” (1000 = M, 900 = CM, 90 = XC) and 2008 is rendered “MMVIII” (2000 = MM, 8 = VIII). The Roman numeral for 1666, “MDCLXVI”, uses each letter in descending order.
注意一点:题目没有描述,当较小的值出现在较大的值之前时,将从较大的值中减去该值。可参考文末的引用链接。
1 | function solution(roman) { |
Write a function dirReduc which will take an array of strings and returns an array of strings with the needless directions removed (W<->E or S<->N side by side).
The Haskell version takes a list of directions with data Direction = North | East | West | South.
The Clojure version returns nil when the path is reduced to nothing.
The Rust version takes a slice of enum Direction {North, East, West, South}.
详细描述可以查看文档底部的引用链接。
1 | function dirReduc(arr) { |
Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone number.
Example
createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) // => returns "(123) 456-7890"
The returned format must be correct in order to complete this challenge.
Don’t forget the space after the closing parentheses!
slice()
方法1 | function createPhoneNumber(numbers) { |