O
O
OldSchoolWeb2018-09-19 10:24:00
JavaScript
OldSchoolWeb, 2018-09-19 10:24:00

How can such a function be implemented in JS?

There is code, you need to wrap it in a function and call the function

var massiveData = {
DataType: 'Key;;Key;;Key;;Sticker;;Sticker;;',
DataCat: 'Normal;;Normal;;Normal;;Normal;;Normal;;Normal;;Normal;;Normal;;Normal;;Normal;;Normal;;Normal;;Normal;;Normal;;Normal;;Normal;;Normal;;Normal;;StatTrak;;Normal;;StatTrak;;StatTrak;;StatTrak;;Normal;;StatTrak;;StatTrak;;StatTrak;;Normal;;StatTrak;;★;;' ,
// GET DATA
};

function getKeys(requestingKey){
var initKey = massiveData; var countKey = 0;
var splittingType = massiveData.DataType.split(';;');

for(i=0;i < splittingType.length;i++){
if(splittingType[i] == requestingKey){countKey = countKey + 1;}else{}
}return countKey;}
getKeys();

function getNormal(requestingSTrack){
var initSTrack = massiveData; var countSTrack = 0;
var splittingCat = massiveData.DataCat.split(';;')
for(i=0;i < splittingCat.length;i++){
if(splittingCat[i] == requestingSTrack){countSTrack = countSTrack + 1;}else{}
}return countSTrack;}
getStatTrack();

console.log(getStatTrack('Normal'));
console.log(getKeys('Key'));

The editor plows, the program does not. Because there is a limitation:
|EVAL| - JS script interpreter (in order for the function to return something, you need to transfer your JS
script to a function and return the desired value and then call this function)
An example of a working code of another option:
#beginScript
|DV|[CountKeysFind] = (|EVAL|
var DataType = 'Key;;Sticker;;Sticker;;Key;;Key;;Key';
var splittingType = DataType.split(';;');
var countKey = 0;
function getKeys(theValue) {
for(i=0;i < splittingType.length;i++){
if(splittingType[i] == theValue){
countKey = countKey + 1;
}
}
return countKey;
}
getKeys('Key');
|EVAL|)

Here it passes the value 4 to |DV|[CountKeysFind] , because it finds 4 key in the array
The function is needed so that I enter |DV|[NameDinamycVal] = (|EVAL|function Name(p1, p2)|EVAL|) , Where p1 - the name of the desired function, where p2 is the value to search.
example: function taskFunctions(getCountShop, 'Stickers') => the getcountshop function was called in which the output will be getCountShop('Strickers');

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question