Skip to content

About

JavaScript Homework 3 — Arrays and Functions: Practical tasks covering array creation, manipulation (slice, concat, join, includes), iteration (for, for…of), and function basics with parameters, return values, and default settings.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📘 JavaScript Homework 3

This repository contains solutions for 3 tasks focused on arrays and functions in JavaScript. Each task is implemented in a separate file (task-1.js, task-2.js, task-3.js).


🔹 Task 1: Slug Creator (task-1.js)

A function was written to generate a slug from a given string.
Slug rules:

  • All characters must be lowercase.
  • Words must be joined with a dash (-).
function slugify(title) {
  return title.toLowerCase().split(" ").join("-");
}

✅ Test Results

slugify("Arrays for begginers"); 
// "arrays-for-begginers"

slugify("English for developer"); 
// "english-for-developer"

slugify("Ten secrets of JavaScript"); 
// "ten-secrets-of-javascript"

slugify("How to become a JUNIOR developer in TWO WEEKS"); 
// "how-to-become-a-junior-developer-in-two-weeks"

🔹 Task 2: Array Composition (task-2.js)

A function that merges two arrays and limits the result by maxLength.

function makeArray(firstArray, secondArray, maxLength) {
  const newArray = firstArray.concat(secondArray);
  if (newArray.length > maxLength) {
    newArray.length = maxLength;
  }
  return newArray;
}

✅ Test Results

makeArray(["Mango", "Poly"], ["Ajax", "Chelsea"], 3); 
// ["Mango", "Poly", "Ajax"]

makeArray(["Mango", "Poly", "Houston"], ["Ajax", "Chelsea"], 4); 
// ["Mango", "Poly", "Houston", "Ajax"]

makeArray(["Mango"], ["Ajax", "Chelsea", "Poly", "Houston"], 3); 
// ["Mango", "Ajax", "Chelsea"]

makeArray(["Earth", "Jupiter"], ["Neptune", "Uranus"], 2); 
// ["Earth", "Jupiter"]

makeArray(["Earth", "Jupiter"], ["Neptune", "Uranus"], 4); 
// ["Earth", "Jupiter", "Neptune", "Uranus"]

makeArray(["Earth", "Jupiter"], ["Neptune", "Uranus", "Venus"], 0); 
// []

🔹 Task 3: Filtering an Array of Numbers (task-3.js)

A function that filters numbers from an array, keeping only those greater than a given value.

function filterArray(numbers, value) {
  const newArray = [];

  for (const number of numbers) {
    if (number > value) {
      newArray.push(number);
    }
  }

  return newArray;
}

✅ Test Results

filterArray([1, 2, 3, 4, 5], 3); 
// [4, 5]

filterArray([1, 2, 3, 4, 5], 4); 
// [5]

filterArray([1, 2, 3, 4, 5], 5); 
// []

filterArray([12, 24, 8, 41, 76], 38); 
// [41, 76]

filterArray([12, 24, 8, 41, 76], 20); 
// [24, 41, 76]

📌 Summary & Reflection

Great progress! 🎉 With this homework, you strengthened your skills in arrays and functions.

Now you know:

  • How arrays work
  • Basic array methods
  • Iteration with for...of loop
  • Writing and using functions effectively
  • The difference between global scope and block scope

It’s time to reinforce this knowledge with practice and keep climbing higher 🚀


📌 Overview

  • Task 1: Slug creation from strings
  • Task 2: Array composition with concat and maxLength limit
  • Task 3: Filtering numbers greater than a given value

About

JavaScript Homework 3 — Arrays and Functions: Practical tasks covering array creation, manipulation (slice, concat, join, includes), iteration (for, for…of), and function basics with parameters, return values, and default settings.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages