Test name | Executions per second |
---|---|
Lodash | 700.0 Ops/sec |
JS some | 695.3 Ops/sec |
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
function getRandomString(length) {
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
let result = "";
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * charset.length);
result += charset.charAt(randomIndex);
}
return result;
}
function getRandomBoolean() {
return Math.random() < 0.5; // Generates true or false with roughly equal probability
}
function generateArrayOfJSONObjects(length) {
const jsonArray = [];
for (let i = 0; i < length; i++) {
const jsonObject = {
name: getRandomString(10), // Change 10 to the desired length of the random string
value: getRandomBoolean(),
};
jsonArray.push(jsonObject);
}
return jsonArray;
}
const array = generateArrayOfJSONObjects(1000);
const found = _.some(array, s => s.value);
const array = generateArrayOfJSONObjects(1000);
const found = array.some(s => s === 'oranges');