Untitled
unknown
plain_text
a year ago
1.9 kB
12
Indexable
// recursion is a way in which function calls itself
// const arr = [1, 2, 3, 4, 5, 6, 7, 8];
// function getSum(index = 0, sum = 0) {
// if (arr.length === index) {
// return sum;
// }
// sum = sum + arr[index];
// index = index + 1;
// return getSum(index, sum)
// }
// console.log(getSum());
// const arr = [11, 22, 33, 44];
// function getLength(ind = 0){
// if(arr[ind]){
// ind = ind + 1;
// getLength(ind)
// }
// arr[0]
// if(11){
// ind = 0 + 1;
// getLength(1)
// }
// arr[1]
// if(22){
// ind = 1 + 1
// getLength(2)
// }
// arr[2]
// if(33){
// ind = 2 + 1;
// getLength(3)
// }
// arr[3]
// if(44){
// ind = ind + 1
// ind = 3 + 1
// getLength(4)
// }
// arr[4]
// if(undefined){
// }else{
// return ind
// }
// }
// const a = getLength();
// console.log(a)
// function getLength(index = 0) {
// if (arr1.length === index) {
// return index;
// }
// else {
// index = index + 1;
// return getLength(index)
// }
// }
// console.log(getLength())
// slice is a method of array for removing the element from the array
// const arr = [11, 22, 33, 44];
// function findLength(arr){
// if(arr.length === 0){
// return 0;
// }
// return 1 + findLength(arr.slice(1))
// 1 + () 1st time
// 1 + 1 () 2nd time
// 1 + 1 + 1 () 3rd time
// 1 + 1 + 1 + 1 () 4th time
// [11,22,33,44]
// 1+ findLength([22,33,44])
// [22,33,44]
// if(3 === 0)
// 1 + [22,33,44]
// 1 + 1 findLength([33,44])
// if(2 === 0)
// 1 + 1 + 1 findLength([44])
// if(1 === 0)
// 1+1+1+1 findLength([])
// }
// console.log(findLength(arr))
// array question based on for loop and while loop
// object and array of objects
// methods of array Editor is loading...
Leave a Comment