Find object (v2)

Revision 2 of this benchmark created on


Description

Find translation of field

Setup

<script>
   function findTranslation (data,  i18nLanguage)  {
        //to map backend response
        const languageID = i18nLanguage === 'en' ? 1 : '2';
        if ( data.length > 0) {
            const record = data.filter((item: any)=> item.language_id === languageID);
            if (record.length > 0) {
                return record[0]?.name;
            }
            else return null;
        }
    }
    let data=[];
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
TEST 1
const data = [ {
        "language_id": 1,
        "language_name": "English",
        "translation_key_id": 421,
        "name": "Lending"
    },
    {
        "language_id": 2,
        "language_name": "French",
        "translation_key_id": 421,
        "name": "Approbation"
    }
    {
        "language_id": 3,
        "language_name": "Spanish",
        "translation_key_id": 421,
        "name": "Aprobacion"
    }
];
const i18nLanguage = 'en';
findTranslation(data, i18nLanguage)
ready
TEST 2
const data = [ {
        "language_id": 1,
        "language_name": "English",
        "translation_key_id": 421,
        "name": "Fraud"
    },
     {
        "language_id": 3,
        "language_name": "Spanish",
        "translation_key_id": 421,
        "name": "Fraude in spanish"
    }
    {
        "language_id": 2,
        "language_name": "French",
        "translation_key_id": 421,
        "name": "Fraude in french"
    }
];
const i18nLanguage = 'fr';  
findTranslation(data, i18nLanguage)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.