GithubHelp home page GithubHelp logo

array-iteration-with-while-for's Introduction

Array-Iteration-with-while-for

Week 1 - Array Iteration with while & for

Basic Requirments

0.Try to write all of the exercises using both the for loop and while loop.

1.Write a function sum that computes the sum of the numbers in an array.

2.Write a function max that accepts an array of numbers and returns the largest number in the array.

3.Try the following at a console:

 'the quick brown fox jumped over the lazy dog'.split(' '); 
 'Hello, world!'.split('') 
 '1,2,3,4,5,6'.split(',')

What is returned by split (You can read more about it here (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) and how does it work? Use split to write a function longestWord that takes a string as an argument and returns the longest word.

4.Write a function remove that accepts an array and an element, and returns an array with all ocurrences of element removed.

function remove(array, element) { 
 // your code here 
 } 
 remove([1, 3, 6, 2, 3], 3); // => [1, 6, 2]

5.Write a function evens that accepts an array as an argument, and returns an array consisting of all of the even numbers in that array.

More Practice

1.Write a function called average that takes an array of numbers as a parameter and returns the average of those numbers.

  1. Write a function called min that finds the smallest number in an array of numbers.

3.Write a function shortestWord that works like longestWord, but returns the shortest word instead.

4.Write a function countChar that takes two arguments: any string, and a character (string of one letter), and returns the number of times that the character occurs in the string.

5.Write a function evenLengthWords that takes an array of strings as an argument, and returns an array of just the words that have an even length.

Advanced

1.Read about the join method on MDN and use it to implement a function that accepts a string as an argument and returns that string reversed

2.Write a function keep that 'keeps' certain elements in an array. The function will need to take two arguments, an array, and something else -- the second argument will be what is used to determine which elements to keep.

You should be able to use this function to write evens, evenLengthWords, a hypothetical odds function, or oddLengthWords without changing the keep function.

array-iteration-with-while-for's People

Contributors

abdelsalamshahlol avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.