Advertisement
LusienGG

[ECMAScript 6] MultipleValuesForKey

Jun 17th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Created by Lusien.GG on 17-06-16.
  3.  */
  4. 'use strict'
  5. function keyValue(input) {
  6.     let collection = []
  7.     for (let i=0; i<input.length-1; i++){
  8.         let tokens = input[i].split(' ')
  9.         let obj = { key: tokens[0],value: tokens[1] }
  10.         collection.push(obj)
  11.     }
  12.     let a = true;
  13.     for ( let obj of collection){
  14.         if (obj.key === input[input.length-1]) {
  15.             console.log(obj.value)
  16.             a = false;
  17.         }
  18.     }
  19.     if(a)
  20.         console.log("None")
  21. }
  22. // keyValue(['key value',
  23. //           'key eulav',
  24. //           'test tset',
  25. //           'key'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement