GithubHelp home page GithubHelp logo

arrays_assignment's Introduction

git# Arrays Lab

To complete this lab (as for most labs), do the following:

  1. Fork this repo.
  2. Clone your forked repo.
  3. Create a file called arrays_lab.js inside your cloned repo.
  4. Copy the description of the exercise as a comment.
  5. Underneath the commented description write your code.
  6. Ensure your solutions work properly!
  7. Open PR against this repo.

Exercises

1. Problem One - Fruits array

a. Add "mango" to the end of a fruits array ["strawberry", "banana"].

b. Add "blueberry" to the front of the same fruits array.

c. Remove the last element of the fruits array.

d. console.log the length of the fruits array.

e. Remove the first element of the fruits array.

f. Join all the elements in the fruits array with a '$'.

2. Problem Two - Larger array

Given two arrays, write code that logs the larger array. If the arrays are the same length, log "They are the same size"

let firstArr = [1,2,3]
let secondArr = [1,5,2,4]

// log [1,5,2,4]

3. Problem Three - Middle element

Given an array, log its middle element. If the middle of the array is between two elements, log both of them.

let hasExactMiddleArr = [1,5,3]

// logs 5

let hasNoExactMiddleArr = [1,4,6,9]

// logs 4,6

4. Problem Four - Iterate over an array

a. Write code that logs every value in an array using a for loop

let logMeOutFor = ["I", "am", "a", "happy", "array"]

/* I
  am
  a
  happy
  array
*/

b. Write code that logs every value in an array using a while loop

let logMeOutWhile = ["I", "am", "a", "happy", "array"]

/* I
  am
  a
  happy
  array
*/

c. Write code that logs every value in an array using a for/of loop

let logMeOutForOf = ["I", "am", "a", "happy", "array"]

/* I
  am
  a
  happy
  array
*/

5. Problem Five - Sum of array

Given an array of numbers, write code that logs the sum of all the numbers

let firstArrToSum = [1, 2, 3, 4, 5, 6]
//  21

let secondArrToSum = [1, 2, 3, 4, 5, -6]
//  9

6. Problem Six - Log odd/even numbers

a. Given an array of numbers, write code that logs all the odd numbers

let evenAndOddArr = [1,5,2,4,11,12,99,100]

// 1, 5, 11, 99

b. Given an array of numbers, write code that logs the sum of all the even numbers

let evenAndOddArrToSum = [1,5,2,3,11,4,6]

// 12

7. Problem Seven - Smallest value

Given an array of numbers, write code that logs the smallest value

let arr = [4,3,7,29,40]

// 3

8. Problem Eight - Second smallest value

Find the second smallest number in an Array of Ints

let secondSmallestArr = [11, 52, 10, 7, 50, 46, 79, 78, 13, 26, 83, 92, 89, 81, 1, 41, 4, 23, 57, 41, 80, 83, 41, 69]

// 4

9. Problem Nine - Duplicates

Write code such that noDupeList has all the same numbers as dupeFriendlyList, but has no more than one of each number.

Hint

Make another array to store all the values you've seen so far. When looking at a new value, see if your array includes the value, and only add it to the noDupeList if it doesn't.

let dupeFriendlyList = [4,2,6,2,2,6,4,9,2,1]
let noDupeList = []

// noDupleList = [4, 2, 6, 9, 1]

arrays_assignment's People

Contributors

benstone1 avatar alejo4373 avatar dakiddj25 avatar

Watchers

James Cloos 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.