Created
September 27, 2017 02:51
-
-
Save haipeng/e1957a8aa84463d4d943918d8ab10a11 to your computer and use it in GitHub Desktop.
根据字符串、字符串数组创建map
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 根据字符串、字符串数组创建map | |
* @param {String|Array<String>} items | |
* @param {String|RegExp} delimiter 默认值/\s+/ | |
* @param {Object} [map] | |
* @returns {{*}} | |
*/ | |
var makeMap = function (items, delimiter, map) { | |
items = items || []; | |
if (typeof items === 'string') { | |
items = items.split(delimiter || /\s+/); | |
} | |
map = map || {}; | |
for (var i = items.length - 1; i >= 0; i--) { | |
map[items[i]] = true; | |
} | |
return map; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment