Create Permutation of Array with Given Number of Elements in JavaScript

AmitDiwan
Updated on 20-Jan-2021 06:45:15

223 Views

We are required to write a JavaScript function that takes in an array of literals as the first argument and a number as the second argument.The function should construct an array of all such arrays which have the length equal to the number specified by the second argument and contains all possible permutations of the elements of the input array.For example −If the input array and the number are −const arr = ['k', 5]; const num = 3;Then the output should be −const output = [    [ 'k', 'k', 'k' ],    [ 'k', 'k', 5 ],    [ ... Read More

Adding Numbers Represented by String in JavaScript

AmitDiwan
Updated on 20-Jan-2021 06:43:24

792 Views

We are required to write a JavaScript function that takes in two strings, str1 and str2 that represents two numbers.Without converting the whole strings to respective numbers, our function should calculate the sum of those two string numbers and return the result as a string.For example −If the two strings are −const str1 = '234'; const str2 = '129';Then the output should be 363.−ExampleFollowing is the code −const str1 = '234'; const str2 = '129'; const addStringNumbers = (str1, str2) => {    let ind1 = str1.length - 1,    ind2 = str2.length - 1,    res = "",   ... Read More

Find the First Non-Repeating Character in a String using JavaScript

AmitDiwan
Updated on 20-Jan-2021 06:41:53

482 Views

We are required to write a JavaScript function that takes in a string as the first and the only argument.The function should find and return the index of first character it encounters in the string which appears only once in the string.If the string does not contain any unique character, the function should return -1.For example −If the input string is −const str = 'hellohe';Then the output should be −const output = 4;ExampleFollowing is the code −const str = 'hellohe'; const firstUnique = (str = '') => {    let obj = {};    for(let i = 0; i < ... Read More

Finding Desired Numbers in a Sorted Array in JavaScript

AmitDiwan
Updated on 20-Jan-2021 06:40:01

200 Views

We have an array of integers which is sorted in the increasing order. We are required to write a JavaScript function that takes in one such array as the first argument and a target sum number as the second argument.The function should find and return two such numbers from the array that when added gives the target sum. The condition for solving this problem is that we have to do this in linear time and using constant space.ExampleFollowing is the code −const arr = [4, 6, 8, 9, 11, 12, 18, 21]; const num = 27; const findElements = (arr ... Read More

Find Length of Second Last Word in a Sentence in JavaScript

AmitDiwan
Updated on 20-Jan-2021 06:37:24

487 Views

A sentence is just a string which contains strings (called words) joined by whitespaces. We are required to write a JavaScript function that takes in one such sentence string and count the number of characters in the second to last word of the string. If the string contains no more than 2 words, our function should return 0.For example −If the input string is −const str = 'this is an example string';Then the output should be −const output = 7;because the number of characters in example is 7.ExampleFollowing is the code −const str = 'this is an example string'; const ... Read More

Finding Element Greater Than Its Adjacent Elements in JavaScript

AmitDiwan
Updated on 20-Jan-2021 06:35:53

487 Views

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 find and return one such number from the array which is greater than both, the number on its immediate right and the number on its immediate left. If there exists more than one such element in the array, our function should return any one of them.For example −If the input array is −const arr = [3, 6, 7, 9, 8, 2, 5];Then the output should be −const output = 9;Since the question demands finding the peak ... Read More

Use TensorFlow to Define Loss Function, Optimizer, and Train Model on IMDB Dataset in Python

AmitDiwan
Updated on 19-Jan-2021 13:44:59

163 Views

Tensorflow is a machine learning framework that is provided by Google. It is an open-source framework used in conjunction with Python to implement algorithms, deep learning applications and much more. It is used in research and for production purposes.The ‘tensorflow’ package can be installed on Windows using the below line of code −pip install tensorflowThe ‘IMDB’ dataset contains reviews of over 50 thousand movies. This dataset is generally used with operations associated with Natural Language Processing.We are using the Google Colaboratory to run the below code. Google Colab or Colaboratory helps run Python code over the browser and requires zero ... Read More

Configure IMDB Dataset for Good Performance in TensorFlow

AmitDiwan
Updated on 19-Jan-2021 13:44:44

167 Views

Tensorflow is a machine learning framework that is provided by Google. It is an open−source framework used in conjunction with Python to implement algorithms, deep learning applications and much more. It is used in research and for production purposes.The ‘tensorflow’ package can be installed on Windows using the below line of code −pip install tensorflowTensor is a data structure used in TensorFlow. It helps connect edges in a flow diagram. This flow diagram is known as the ‘Data flow graph’. Tensors are nothing but multidimensional array or a list.The ‘IMDB’ dataset contains reviews of over 50 thousand movies. This dataset ... Read More

Prepare IMDB Dataset for Training in Python using TensorFlow

AmitDiwan
Updated on 19-Jan-2021 13:43:21

184 Views

Tensorflow is a machine learning framework that is provided by Google. It is an open−source framework used in conjunction with Python to implement algorithms, deep learning applications and much more. It is used in research and for production purposes. It has optimization techniques that help in performing complicated mathematical operations quickly.The ‘tensorflow’ package can be installed on Windows using the below line of code −pip install tensorflowTensor is a data structure used in TensorFlow. It helps connect edges in a flow diagram. This flow diagram is known as the ‘Data flow graph’. Tensors are nothing but multidimensional array or a ... Read More

Download and Explore IMDB Dataset using TensorFlow in Python

AmitDiwan
Updated on 19-Jan-2021 13:42:43

355 Views

Tensorflow is a machine learning framework that is provided by Google. It is an open−source framework used in conjunction with Python to implement algorithms, deep learning applications and much more. It is used in research and for production purposes.This is because it uses NumPy and multi−dimensional arrays. These multi-dimensional arrays are also known as ‘tensors’. The framework supports working with deep neural network. It is highly scalable, and comes with many popular datasets. It uses GPU computation and automates the management of resources. It comes with multitude of machine learning libraries, and is well-supported and documented. The framework has the ... Read More

Advertisements