Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const nums = [23, 45, 3, 2, 6, 7, 8, 8, 90, 87, 65, 4, 3, 2];//test data
- const line = () => {
- console.log('-'.repeat(50))
- };//print pseudo line
- const times = 1000000;//repeating cycle
- //========================================
- //high order function filter()
- console.time('high order function: filter()');
- for (let indx = 0; indx < times; indx += 1) {
- const filtered = nums.filter((a) => a >= 21);
- }
- console.timeEnd('high order function: filter()');
- line();
- //========================================
- //naive approach
- console.time('naive approach');
- for (let indx = 0; indx < times; indx += 1) {
- const filtered = [];
- for (let e = 0; e < nums.length; e += 1) {
- if (e >= 21) {
- filtered.push(e);
- }
- }
- }
- console.timeEnd('naive approach')
- line();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement