We are required to write a JavaScript function that takes in a number, num as the only argument. The function should first construct an array of n elements based on the following rule −arr[i] = (2 * i) + 1;Therefore, if the input number is 5, then the array should be −const arr = [1, 3, 5, 7, 9];Our function is supposed to calculate and return the minimum number of steps it should take so that all the elements of the array become equal.Let us now define one step −One valid step consists of choosing any two numbers from the ... Read More
We are required to write a JavaScript function that takes in an array of Integers as the first and the only argument. The function should then construct and return a new array that contains only those elements from the original array that contains an even number of digits.For example −If the input array is −const arr = [12, 6, 123, 3457, 234, 2];Then the output should be −const output = [12, 3457];ExampleThe code for this will be − Live Democonst arr = [12, 6, 123, 3457, 234, 2]; const findEvenDigitsNumber = (arr = []) => { const res = []; ... Read More
Suppose, we have an array of objects that contains information about some students and the marks scored by them over a period of time like this −const marks = [ { id: 231, score: 34 }, { id: 233, score: 37 }, { id: 231, score: 31 }, { id: 233, score: 39 }, { id: 231, score: 44 }, { id: 233, score: 41 }, { id: 231, score: 38 }, { id: 231, score: 31 }, { id: 233, score: 29 }, { id: 231, score: 34 }, ... Read More
We are required to write a JavaScript function that takes in an array of integers, arr, as the first argument and a number, num (num < length of arr) as the second argument. The function should construct and return a new array that contains the average of all possible num contiguous numbers of the array.For example −If the input array and the number are −const arr = [1, 2, 3, 4, 5]; const num = 2;Then the output should be −const output = [1.5, 2.5, 3.5, 4.5];because the possible continuous windows of size two are (1, 2), (2, 3), (3, ... Read More
We are required to write a JavaScript function that takes in an array of numbers as the first and the only argument. The function should return true if all the numbers in the array appear only once (i.e., all the numbers are unique), and false otherwise.For example −If the input array is −const arr = [12, 45, 6, 34, 12, 57, 79, 4];Then the output should be −const output = false;because the number 12 appears twice in the array.ExampleThe code for this will be − Live Democonst arr = [12, 45, 6, 34, 12, 57, 79, 4]; const containsAllUnique = (arr ... Read More
We are required to write a JavaScript function that takes in an array of Integers as the first and the only argument.The function should then iterate through the array and pick that largest number from the array which only appeared once in the array. After that, return this number and if there is no unique number in the array, we should return -1.We are also told that the maximum value of any array element will not exceed 100 and will be greater than 0 which mean −0 < arr[i] < 101for all i within the array index.For example −If the ... Read More
We are required to write a JavaScript function that takes in an array of numbers as the first and the only argument.The function should then construct and return a new array based on the original array.The new array should contain all those elements from the original array whose value was equal to the index they were placed on.Note that we have to check the value and index using 1-based index and not the traditional 0- based index.For example −If the input array is −const arr = [45, 5, 2, 4, 6, 6, 6];Then the output should be −const output = ... Read More
We are required to write a JavaScript function that takes in a string as the first and the only argument.The task of our function is to check whether any rearrangement in the characters of the string results into a palindrome string or not. If yes, then our function should return true, false otherwise.For example −If the input string is −const str = 'amadm';Then the output should be −const output = true;because the string can be rearranged to form 'madam' which is a palindrome string.ExampleThe code for this will be − Live Democonst str = 'amadm'; const canFormPalindrome = (str = '') ... Read More
We are required to write a JavaScript function that takes in a string str as the first argument and an array of strings, arr as the second argument. We need to add a closed pair of paragraph tag and to wrap the substrings in str that exist in arr. If two such substrings overlap, we need to wrap them together by only one pair of closed paragraph tag.Also, if two substrings wrapped by paragraph tags are consecutive, we need to combine them.For example −If the input string and the array are −const str = 'kkkllmm'; const arr = ... Read More
Tensorflow can be used to create a model that tracks internal layers by creating a sequential model and using this model to call ‘tf.zeros’ method.Read More: What is TensorFlow and how Keras work with TensorFlow to create Neural Networks?A neural network that contains at least one layer is known as a convolutional layer. We can use the Convolutional Neural Network to build learning model. The intuition behind transfer learning for image classification is, if a model is trained on a large and general dataset, this model can be used to effectively serve as a generic model for the visual world. It ... Read More