How to find the order changed contents in arrays using javascript? -


    ex : original array : =[1,2,3,4,g,5]      if user wrongly entered above array :   = [2,1,3,4,g,5]  

how find position changed element original array list using javascript ?(i.e. [1,2] have been changed).

// try entering @ prompt: [2, 1, 3, 4, 'g', 5]  var original = [1, 2, 3, 4, 'g', 5],     input = eval(prompt('enter array please.'));  input.foreach(function (element, index) {     var expected = original[index];     if (element !== expected) {         // different.         // logic handle difference goes here. example:         console.log('elements different; ' +                     'expected `' + expected + '\', ' +                     'got `' + element + '\'.');     } }); 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -