注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
本帖最后由 匿名 于 2021-5-11 03:45 编辑
今天刚面完,地里原题http header那道,高频。 约了onsite 希望好运, 顺带求点大米 :)
// In an HTTP request, the Accept-Language header describes the list of
// languages that the requester would like content to be returned in. The header
// takes the form of a comma-separated list of language tags. For example:
//
// Accept-Language: en-US, fr-CA, fr-FR
//
// means that the reader would accept:
//
// 1. English as spoken in the United States (most preferred)
// 2. French as spoken in Canada
// 3. French as spoken in France (least preferred)
//
// We're writing a server that needs to return content in an acceptable language
// for the requester, and we want to make use of this header. Our server doesn't
// support every possible language that might be requested (yet!), but there is a
// set of languages that we do support. Write a function that receives two arguments:
// an Accept-Language header value as a string and a set of supported languages,
// and returns the list of language tags that will work for the request. The
// language tags should be returned in descending order of preference (the
// same order as they appea
// Examples:
//
// parse_accept_language("fr-FR;q=1, fr-CA;q=0, fr;q=0.5", ["fr-FR", "fr-CA", "fr-BG"])
// returns: ["fr-FR", "fr-BG", "fr-CA"]
//
// parse_accept_language("fr-FR;q=1, fr-CA;q=0, *;q=0.5", ["fr-FR", "fr-CA", "fr-BG", "en-US"])
// returns: ["fr-FR", "fr-BG", "en-US", "fr-CA"]
//
// parse_accept_language("en-US;q=1, en;q=0.5, *;q=0", ["en-GB", "en-US", "fr-CA", "fr-FR"])
// returns: ["en-US", "en-GB", "fr-CA", "fr-FR"]
|