Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
foreach vs reduce
(version: 0)
Comparing performance of:
reduce foreach filter vs foreach foreach filter
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
dictionary = ['hack', 'a', 'rank', 'khac', 'ackh', 'kran', 'rankhacker', 'a', 'ab', 'ba', 'stairs', 'raits'] query = ["a", "nark", "bs", "hack", "stair"]
Tests:
reduce foreach filter
function name() { const sortedDictionary = dictionary.reduce((sorted, el) => { sorted.push(el.split('').sort().join('')) return sorted }, []) let count = 0 query.foreach(el => { sortedQuery = el.split('').sort().join('') count = sortedDictionary.filter(el => (el == sortedQuery).length) console.log(count) }) }
foreach foreach filter
function sorting(array) { let sortedArray = [] array.forEach((el) => { sortedArray.push(el.split('').sort().join('')) }) return sortedArray } function stringAnagram(dictionary, query) { // Write your code here let sortedDictionary = sorting(dictionary) let sortedQuery = sorting(query) let count=0 let counting=[] for (let i = 0; i < sortedQuery.length; i++) { count = sortedDictionary.filter((v) => (v === sortedQuery[i])).length; counting.push(count) } return counting }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
reduce foreach filter
foreach foreach filter
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
jQuery.each() vs Array.prototype.forEach()
reduce spread vs reduce
Spread operator vs Push vs Concat in reduce (add array)
Simple Array Find vs Includes
jQuery $.each() vs Array.prototype.forEach()
Comments
Confirm delete:
Do you really want to delete benchmark?