/Array__Functions

Stutern Week 4 Assignment

Primary LanguageJavaScript

Arrays & Functions

๐˜๐˜ฐ๐˜ณ ๐˜ต๐˜ฉ๐˜ช๐˜ด ๐˜ข๐˜ด๐˜ด๐˜ช๐˜จ๐˜ฏ๐˜ฎ๐˜ฆ๐˜ฏ๐˜ต, ๐˜ค๐˜ณ๐˜ฆ๐˜ข๐˜ต๐˜ฆ ๐˜ข ๐˜ง๐˜ฐ๐˜ญ๐˜ฅ๐˜ฆ๐˜ณ ๐˜ข๐˜ฏ๐˜ฅ ๐˜ฏ๐˜ข๐˜ฎ๐˜ฆ ๐˜ช๐˜ต ๐˜ข๐˜ณ๐˜ณ๐˜ข๐˜บ๐˜ด-๐˜ง๐˜ถ๐˜ฏ๐˜ค๐˜ต๐˜ช๐˜ฐ๐˜ฏ๐˜ด. ๐˜Š๐˜ณ๐˜ฆ๐˜ข๐˜ต๐˜ฆ ๐˜ข๐˜ฏ โ€˜๐˜ช๐˜ฏ๐˜ฅ๐˜ฆ๐˜น.๐˜ซ๐˜ดโ€™ ๐˜ง๐˜ช๐˜ญ๐˜ฆ ๐˜ข๐˜ฏ๐˜ฅ ๐˜ฑ๐˜ถ๐˜ต ๐˜ข๐˜ญ๐˜ญ ๐˜บ๐˜ฐ๐˜ถ๐˜ณ ๐˜ข๐˜ฏ๐˜ด๐˜ธ๐˜ฆ๐˜ณ๐˜ด ๐˜ช๐˜ฏ ๐˜ต๐˜ฉ๐˜ฆ๐˜ณ๐˜ฆ. ๐˜š๐˜ฆ๐˜ฑ๐˜ข๐˜ณ๐˜ข๐˜ต๐˜ฆ ๐˜บ๐˜ฐ๐˜ถ๐˜ณ ๐˜ข๐˜ฏ๐˜ด๐˜ธ๐˜ฆ๐˜ณ๐˜ด ๐˜ถ๐˜ด๐˜ช๐˜ฏ๐˜จ ๐˜ค๐˜ฐ๐˜ฎ๐˜ฎ๐˜ฆ๐˜ฏ๐˜ต๐˜ด. ๐˜—๐˜ถ๐˜ด๐˜ฉ ๐˜บ๐˜ฐ๐˜ถ๐˜ณ ๐˜ธ๐˜ฐ๐˜ณ๐˜ฌ ๐˜ช๐˜ฏ๐˜ต๐˜ฐ ๐˜ข ๐˜Ž๐˜ช๐˜ต๐˜ฉ๐˜ถ๐˜ฃ ๐˜ณ๐˜ฆ๐˜ฑ๐˜ฐ๐˜ด๐˜ช๐˜ต๐˜ฐ๐˜ณ๐˜บ ๐˜ข๐˜ฏ๐˜ฅ ๐˜ด๐˜ถ๐˜ฃ๐˜ฎ๐˜ช๐˜ต ๐˜ต๐˜ฉ๐˜ฆ ๐˜Ž๐˜ช๐˜ต๐˜ฉ๐˜ถ๐˜ฃ ๐˜ณ๐˜ฆ๐˜ฑ๐˜ฐ๐˜ด๐˜ช๐˜ต๐˜ฐ๐˜ณ๐˜บ ๐˜ญ๐˜ช๐˜ฏ๐˜ฌ ๐˜ช๐˜ฏ ๐˜Š๐˜ช๐˜ต๐˜ณ๐˜ฐ๐˜ฏ๐˜ฆ.

Questions

๐Ÿ›  Question 1

What are the differences between mutating array methods and non-mutation array methods in JavaScript. List 5 array methods that fall under each of them.

๐Ÿš€ Answer

Mutation in context of JavaScript arrays is basically changing the array itself instead of returning a new array with the new changes.

Examples of 5 Array methods that fall under mutating are:

  • array.pop()
  • array.splice()
  • array.unshift()
  • array.reverse()
  • array.sort()

Non-Mutation is returning a whole new array which has all the changes.

Examples of 5 Array methods that fall under mutating are:

  • array.concat()
  • array.indexOf
  • array.toString()
  • array.join()
  • array.toLocaleString()

๐Ÿ›  Question 2

Here is an array of languages: [โ€˜C#โ€™, โ€˜JavaScriptโ€™, โ€˜Rubyโ€™, โ€˜PHPโ€™, โ€˜Pythonโ€™]. Perform this operation on them Add โ€˜Kotlinโ€™ to the end of the array Add โ€˜Javaโ€™ after โ€˜Rubyโ€™ Remove the first item in the array Add โ€™Scalaโ€™ and โ€˜Swiftโ€™ to the beginning of the array Replace โ€˜PHPโ€™ with โ€˜Goโ€™ and โ€˜Rustโ€™

๐Ÿ›  Question 3

What will be the value of fruit after calling the function changeFruit? let fruit = ['apple', 'mango', 'banana']; function changeFruit( fruit ) { fruit[2] = "orange"; return fruit; }

๐Ÿ›  Question 4

Write a function that accepts an array of numbers as an argument. Return the maximum value in the array. e.g., max([4, 5, 10, -2]) // maximum value is 10

๐Ÿ›  Question 5

Write a function called valTimesIndex which accepts an array of numbers and returns a new array with each value multiplied by the index it is at in the array: e.g., valTimesIndex([1,2,3]) // [0,2,6] valTimesIndex([5,10,15]) // [0,10,30]