d93865a0638d04183f82ab2a17aab5bb.json
9.9 KB
{"ast":null,"code":"/**\n * @fileoverview This module has some functions for handling array.\n * @author NHN.\n * FE Development Lab <dl_javascript@nhn.com>\n */\n'use strict';\n\nvar collection = require('./collection');\n\nvar type = require('./type');\n\nvar aps = Array.prototype.slice;\nvar util;\n/**\n * Generate an integer Array containing an arithmetic progression.\n * @param {number} start - start index\n * @param {number} stop - stop index\n * @param {number} step - next visit index = current index + step\n * @returns {Array}\n * @memberof tui.util\n * @example\n * //-- #1. Get Module --//\n * var util = require('tui-code-snippet'); // node, commonjs\n * var util = tui.util; // distribution file\n *\n * //-- #2. Use property --//\n * util.range(5); // [0, 1, 2, 3, 4]\n * util.range(1, 5); // [1,2,3,4]\n * util.range(2, 10, 2); // [2,4,6,8]\n * util.range(10, 2, -2); // [10,8,6,4]\n */\n\nvar range = function (start, stop, step) {\n var arr = [];\n var flag;\n\n if (type.isUndefined(stop)) {\n stop = start || 0;\n start = 0;\n }\n\n step = step || 1;\n flag = step < 0 ? -1 : 1;\n stop *= flag;\n\n for (; start * flag < stop; start += step) {\n arr.push(start);\n }\n\n return arr;\n};\n/* eslint-disable valid-jsdoc */\n\n/**\n * Zip together multiple lists into a single array\n * @param {...Array}\n * @returns {Array}\n * @memberof tui.util\n * @example\n * //-- #1. Get Module --//\n * var util = require('tui-code-snippet'); // node, commonjs\n * var util = tui.util; // distribution file\n *\n * //-- #2. Use property --//\n * var result = util.zip([1, 2, 3], ['a', 'b','c'], [true, false, true]);\n * console.log(result[0]); // [1, 'a', true]\n * console.log(result[1]); // [2, 'b', false]\n * console.log(result[2]); // [3, 'c', true]\n */\n\n\nvar zip = function () {\n /* eslint-enable valid-jsdoc */\n var arr2d = aps.call(arguments);\n var result = [];\n collection.forEach(arr2d, function (arr) {\n collection.forEach(arr, function (value, index) {\n if (!result[index]) {\n result[index] = [];\n }\n\n result[index].push(value);\n });\n });\n return result;\n};\n/**\n * Returns the first index at which a given element can be found in the array\n * from start index(default 0), or -1 if it is not present.<br>\n * It compares searchElement to elements of the Array using strict equality\n * (the same method used by the ===, or triple-equals, operator).\n * @param {*} searchElement Element to locate in the array\n * @param {Array} array Array that will be traversed.\n * @param {number} startIndex Start index in array for searching (default 0)\n * @returns {number} the First index at which a given element, or -1 if it is not present\n * @memberof tui.util\n * @example\n * //-- #1. Get Module --//\n * var util = require('tui-code-snippet'); // node, commonjs\n * var util = tui.util; // distribution file\n *\n * //-- #2. Use property --//\n * var arr = ['one', 'two', 'three', 'four'];\n * var idx1 = util.inArray('one', arr, 3); // -1\n * var idx2 = util.inArray('one', arr); // 0\n */\n\n\nvar inArray = function (searchElement, array, startIndex) {\n var i;\n var length;\n startIndex = startIndex || 0;\n\n if (!type.isArray(array)) {\n return -1;\n }\n\n if (Array.prototype.indexOf) {\n return Array.prototype.indexOf.call(array, searchElement, startIndex);\n }\n\n length = array.length;\n\n for (i = startIndex; startIndex >= 0 && i < length; i += 1) {\n if (array[i] === searchElement) {\n return i;\n }\n }\n\n return -1;\n};\n\nutil = {\n inArray: inArray,\n range: range,\n zip: zip\n};\nmodule.exports = util;","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/tui-code-snippet/src/js/array.js"],"names":["collection","require","type","aps","Array","prototype","slice","util","range","start","stop","step","arr","flag","isUndefined","push","zip","arr2d","call","arguments","result","forEach","value","index","inArray","searchElement","array","startIndex","i","length","isArray","indexOf","module","exports"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA;;AAEA,IAAIA,UAAU,GAAGC,OAAO,CAAC,cAAD,CAAxB;;AACA,IAAIC,IAAI,GAAGD,OAAO,CAAC,QAAD,CAAlB;;AAEA,IAAIE,GAAG,GAAGC,KAAK,CAACC,SAAN,CAAgBC,KAA1B;AACA,IAAIC,IAAJ;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAIC,KAAK,GAAG,UAASC,K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AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,IAAII,OAAO,GAAG,UAASC,aAAT,EAAwBC,KAAxB,EAA+BC,UAA/B,EAA2C;AACrD,MAAIC,CAAJ;AACA,MAAIC,MAAJ;AACAF,EAAAA,UAAU,GAAGA,UAAU,IAAI,CAA3B;;AAEA,MAAI,CAACzB,IAAI,CAAC4B,OAAL,CAAaJ,KAAb,CAAL,EAA0B;AACtB,WAAO,CAAC,CAAR;AACH;;AAED,MAAItB,KAAK,CAACC,SAAN,CAAgB0B,OAApB,EAA6B;AACzB,WAAO3B,KAAK,CAACC,SAAN,CAAgB0B,OAAhB,CAAwBb,IAAxB,CAA6BQ,KAA7B,EAAoCD,aAApC,EAAmDE,UAAnD,CAAP;AACH;;AAEDE,EAAAA,MAAM,GAAGH,KAAK,CAACG,MAAf;;AACA,OAAKD,CAAC,GAAGD,UAAT,EAAqBA,UAAU,IAAI,CAAd,IAAmBC,CAAC,GAAGC,MAA5C,EAAoDD,CAAC,IAAI,CAAzD,EAA4D;AACxD,QAAIF,KAAK,CAACE,CAAD,CAAL,KAAaH,aAAjB,EAAgC;AAC5B,aAAOG,CAAP;AACH;AACJ;;AAED,SAAO,CAAC,CAAR;AACH,CArBD;;AAuBArB,IAAI,GAAG;AACHiB,EAAAA,OAAO,EAAEA,OADN;AAEHhB,EAAAA,KAAK,EAAEA,KAFJ;AAGHQ,EAAAA,GAAG,EAAEA;AAHF,CAAP;AAMAgB,MAAM,CAACC,OAAP,GAAiB1B,IAAjB","sourcesContent":["/**\n * @fileoverview This module has some functions for handling array.\n * @author NHN.\n * FE Development Lab <dl_javascript@nhn.com>\n */\n\n'use strict';\n\nvar collection = require('./collection');\nvar type = require('./type');\n\nvar aps = Array.prototype.slice;\nvar util;\n\n/**\n * Generate an integer Array containing an arithmetic progression.\n * @param {number} start - start index\n * @param {number} stop - stop index\n * @param {number} step - next visit index = current index + step\n * @returns {Array}\n * @memberof tui.util\n * @example\n * //-- #1. Get Module --//\n * var util = require('tui-code-snippet'); // node, commonjs\n * var util = tui.util; // distribution file\n *\n * //-- #2. Use property --//\n * util.range(5); // [0, 1, 2, 3, 4]\n * util.range(1, 5); // [1,2,3,4]\n * util.range(2, 10, 2); // [2,4,6,8]\n * util.range(10, 2, -2); // [10,8,6,4]\n */\nvar range = function(start, stop, step) {\n var arr = [];\n var flag;\n\n if (type.isUndefined(stop)) {\n stop = start || 0;\n start = 0;\n }\n\n step = step || 1;\n flag = step < 0 ? -1 : 1;\n stop *= flag;\n\n for (; start * flag < stop; start += step) {\n arr.push(start);\n }\n\n return arr;\n};\n\n/* eslint-disable valid-jsdoc */\n/**\n * Zip together multiple lists into a single array\n * @param {...Array}\n * @returns {Array}\n * @memberof tui.util\n * @example\n * //-- #1. Get Module --//\n * var util = require('tui-code-snippet'); // node, commonjs\n * var util = tui.util; // distribution file\n *\n * //-- #2. Use property --//\n * var result = util.zip([1, 2, 3], ['a', 'b','c'], [true, false, true]);\n * console.log(result[0]); // [1, 'a', true]\n * console.log(result[1]); // [2, 'b', false]\n * console.log(result[2]); // [3, 'c', true]\n */\nvar zip = function() {/* eslint-enable valid-jsdoc */\n var arr2d = aps.call(arguments);\n var result = [];\n\n collection.forEach(arr2d, function(arr) {\n collection.forEach(arr, function(value, index) {\n if (!result[index]) {\n result[index] = [];\n }\n result[index].push(value);\n });\n });\n\n return result;\n};\n\n/**\n * Returns the first index at which a given element can be found in the array\n * from start index(default 0), or -1 if it is not present.<br>\n * It compares searchElement to elements of the Array using strict equality\n * (the same method used by the ===, or triple-equals, operator).\n * @param {*} searchElement Element to locate in the array\n * @param {Array} array Array that will be traversed.\n * @param {number} startIndex Start index in array for searching (default 0)\n * @returns {number} the First index at which a given element, or -1 if it is not present\n * @memberof tui.util\n * @example\n * //-- #1. Get Module --//\n * var util = require('tui-code-snippet'); // node, commonjs\n * var util = tui.util; // distribution file\n *\n * //-- #2. Use property --//\n * var arr = ['one', 'two', 'three', 'four'];\n * var idx1 = util.inArray('one', arr, 3); // -1\n * var idx2 = util.inArray('one', arr); // 0\n */\nvar inArray = function(searchElement, array, startIndex) {\n var i;\n var length;\n startIndex = startIndex || 0;\n\n if (!type.isArray(array)) {\n return -1;\n }\n\n if (Array.prototype.indexOf) {\n return Array.prototype.indexOf.call(array, searchElement, startIndex);\n }\n\n length = array.length;\n for (i = startIndex; startIndex >= 0 && i < length; i += 1) {\n if (array[i] === searchElement) {\n return i;\n }\n }\n\n return -1;\n};\n\nutil = {\n inArray: inArray,\n range: range,\n zip: zip\n};\n\nmodule.exports = util;\n"]},"metadata":{},"sourceType":"script"}