alinarub / animalstrings

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Array Methods 2: A simple String Array

This CodeSandbox offers some exercises to recap some advanced array methods. Let's dive in!

Task

In the ./index.js file, there is an animalStrings array with - guess what? - animal names as strings.

Below this array, you will find a couple of variables (e.g. hippoExists). They all are initialized with null.

And now it's your turn: delete the value null and write code such that the variables have a value corresponding to their name. Use the following methods to achieve this goal:

  • Array.includes()
  • Array.find()
  • Array.findIndex()
  • Array.sort()
  • Array.some()
  • Array.every()
  • Array.reduce()

Additionally, you will need:

  • String.startsWith()
  • String.endsWith()

You will find some hints as comments.

Switch to the ./index.js file and work with animals!

Notes

  • If you want to check whether you solved the tasks correctly, open the "Tests" tab of Codesandbox.

Development

❗️ This project is JavaScript only. Please check the browser console (I) for the output or run the tests to see the results.

Local Development

To work locally, please install the dependencies using npm i first.

Run npm run start to start a development server and open localhost:3000 in a browser.

Alternatively you can use the Live Preview Extension for Visual Studio Code to view this project.
Select the HTML file you want to view, press P, search for Live Preview: Show Preview and confirm with Enter.

Use npm run test to run the tests.

CodeSandbox Cloud

Select the "Preview: 3000" tab to view this project.

Select the "Tests: logs" tab to view the tests.

The npm run start and npm run test scripts run automatically.

Scripts

You can use the following commands:

  • npm run start to start a development server
  • npm run test to run the tests
  • npm run lint to run the linter

About


Languages

Language:JavaScript 88.6%Language:HTML 11.4%